Simple Java Graphic Program Not Displaying -
basically i'm starting learn graphics in java made simple program display 2 rectangles , string on screen. program compiles fine not display 2 rectangles or string. input on problem appreciated.
//classone.java import javax.swing.*; public class classone { public static void main(string[] args) { jframe f = new jframe("title"); f.setdefaultcloseoperation(jframe.exit_on_close); classtwo object = new classtwo(); f.add(object); //add object frame f.setsize(400,250); f.setvisible(true); } } //classtwo.java import java.awt.*; import java.awt.event.*; import javax.swing.*; public class classtwo extends jpanel { public void paintcomponet(graphics g) //takes object graphics class { super.paintcomponent(g); this.setbackground(color.black); g.setcolor(color.white); g.fillrect(25, 25, 100, 30); //x,y,width, height g.setcolor(new color(190,81,215)); g.fillrect(25, 70, 100, 30); g.setcolor(color.red); g.drawstring("text", 25, 120); system.out.print("hi"); } }
it's
public void paintcomponent(graphics g)
not
public void paintcomponet(graphics g) {
add @override
annotation allow compiler check method
Comments
Post a Comment