Quote (Eep @ 4 Feb 2013 15:50)
curious but why do they have the same name and same args?
I just realized my problem. lol
Code
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Wagon extends JFrame
implements ActionListener {
private JButton button;
private JPanel panel;
public static void main(String[] args) {
Wagon frame = new Wagon();
frame.setSize(1000, 1000);
frame.createGUI();
frame.setVisible(true);
}
private void createGUI() {
setDefaultCloseOperation(EXIT_ON_CLOSE);
Container window = getContentPane();
window.setLayout(new FlowLayout() );
panel = new JPanel();
panel.setPreferredSize(new Dimension(500, 500));
panel.setBackground(Color.white);
window.add(panel);
button = new JButton("Press me");
window.add(button);
button.addActionListener(this);
}
public void actionPerformed(ActionEvent event) {
Graphics g = panel.getGraphics();
g.setColor(Color.blue);
g.drawLine(50, 60, 100, 100);
// g.drawLine( 100, 100, 0 , 100);
// g.drawLine( 0 ,0, 0 , 100);
setBackground(Color.yellow);
g.setColor(Color.cyan);
// g.fillRect(120,120,200,100);
g.setColor(Color.red);
g.fillRect(120,120,200,100);
// g.fillRect(180,20,60,60);
g.drawOval(0, 0, 100, 100);
g.drawOval(500, 100, 200, 100);
g.drawRect(0,0,70,90);
g.fillArc(0,0,70,90,180,180);
g.setColor(Color.red);
g.drawArc(0,0,100,100,80,80);
}
}
It should look like this. Is there a way to clean it up so it doesn't look so messy all closed together? Also my other problem is I can see my Oval (Which will be a circle). So far I have this coded as the last part.
Code
public void actionPerformed(ActionEvent event) {
Graphics g = panel.getGraphics();
g.setColor(Color.blue);
g.drawLine(50, 60, 100, 100);
// g.drawLine( 100, 100, 0 , 100);
// g.drawLine( 0 ,0, 0 , 100);
setBackground(Color.yellow);
g.setColor(Color.cyan);
// g.fillRect(120,120,200,100);
g.setColor(Color.red);
g.fillRect(120,120,200,100);
// g.fillRect(180,20,60,60);
g.fillOval(140, 140, 50, 50);
g.setColor(Color.green);
}
}
I got rid of the top stuff and just added the oval. I tried draw and fill yet the oval(circle) won't appear.