This program is supposed to output some shapes using the GUI. I can't get it to actually output the shapes, but the panel shows up fine. Could someone show me what I am doing wrong?
This one does the Panel and all that other stuff.
package pregui;
import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Graphics;
public class PreGUI {
public static void main(String[] args) {
// TODO code application logic here
JFrame myFrame = new JFrame();
DrawShape myshape = new DrawShape();
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myFrame.add(myshape);
myFrame.setSize(200, 200);
myFrame.setVisible(true);
}
}
class DrawShape extends JPanel
{
public void paintComponent (Graphics g)
{
g.setColor(Color. red);
g.drawOval(70, 70, 25, 25);
}
}
This one is where the shapes are made. I am not sure about the repaint() but it doesn't work without it either.
package guiproject;
import java.awt.*;
import javax.swing.*;
public class DrawClass extends JPanel {
public void drawing ()
{
repaint();
}
}
class Moon extends JPanel{
public void paintComponent(Graphics g){
super.paintComponent(g);
g.setColor(Color.RED);
g.fillOval(50,50,100,100);
g.setColor(Color.white);
g.fillArc(50, 50, 100, 100, 0, 180);
g.setColor(Color.black);
g.drawLine(50, 100, 150, 100);
}
}