Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  TestPaintComponents
Language: JAVA
Code:
import javax.swing.*;
import java.awt.Graphics;

public class TestPaintComponents extends JFrame { 
     public TestPaintComponents (){
          add(new NewPanel());
     }

     public static void main (String[] args){
          TestPaintComponents frame = new TestPaintComponents();
          frame.setTitle("Test");
          frame.setSize(200,200);
          frame.setLocationRelativeTo(null);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setVisible(true);
     }

     class NewPanel extends JPanel{
          @Override
          protected void paintComponent(Graphics g){
                    super.paintComponent(g);
                    g.drawLine(0,0,50,50);
                    g.drawString("Testing",60,60);
          }
     }
}
Comments: