So I've been getting back into Java and downloaded eclipse back onto my laptop. However when I go to make a simple rectangle into a JFrame, the frame will pop up but no rectangle will be shown. Could any of you please provide assistance?
Here is my main class, which sets up the JFrame...
i mport javax.swing.JFrame; public class Frame{ public static void main(String[] args) { JFrame frame = new JFrame(); frame.setTitle("I hope this fucking works"); frame.setSize(400,400); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); rectangle component = new rectangle(); frame.add(component); frame.setVisible(true); } }
Here is the class that sets up the rectangle....
import java.awt.Graphics; import java.awt.Graphics2D; import javax.swing.JComponent; import java.awt.Rectangle; public class rectangle extends JComponent { public void draw(Graphics g){ Graphics2D g2 = (Graphics2D) g; Rectangle box = new Rectangle(10,10,50,50); g2.draw(box); } }
Thanks for your time and consideration