Results 1 to 4 of 4
Thread: Very new to Java
- 09-06-2012, 10:43 PM #1
Member
- Join Date
- Sep 2012
- Posts
- 2
- Rep Power
- 0
Very new to Java
Hello,
I'm very new to Java and my professor laid this on me on the first week of school.
import javax.swing.*;
import java.awt.Graphics;
import java.awt.Color;
public class MyDrawing_Start extends JFrame {
public MyDrawing_Start() {
add (new MyPanel());
}
public static void main (String [] args){
MyDrawing_Start frame = new MyDrawing_Start();
frame.setTitle("My drawing demo");
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
frame.setSize(250, 350);
frame.setVisible(true);
}
}
class MyPanel extends JPanel {
I've sat here all day trying to understand what is going on in this program and he has asked me to alter the program so that it produces multiple lines (Didn't specify how many). He want to do it as a loop. I understand how to create a loop and all but I think my main problem is that I don't get what is going on here so I don't even know where to start. Am I supposed to start the loop in the "class Mypanel extends JPanel area" area. Any guidance would be appreciated. Thanks.
- 09-06-2012, 10:56 PM #2
Member
- Join Date
- Sep 2012
- Posts
- 2
- Rep Power
- 0
Re: Very new to Java
sorry forgot about this whole section
class MyPanel extends JPanel {
protected void paintComponent(Graphics g) {
super.paintComponent(g);
// For color use the either the next 2 lines or g.setColor(Color.BLUE);
Color myColor = new Color(0, 0, 255);
g.setColor(myColor);
g.drawLine(10, 20, 50, 50);
}
}
- 09-07-2012, 01:09 AM #3
Re: Very new to Java
Forum Rules -- particularly the third paragraph
Guide For New Members
BB Code List - Java Programming Forum
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 09-07-2012, 03:04 AM #4


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks