- //第一部分
- import javax.swing.*;
- import java.awt.*;
- public class HelloCsdn
- {
- public static void main(String[] args)
- {
- HelloCsdnFrame frame=new HelloCsdnFrame();
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.show();
- }
- }
- //第二部分
- class HelloCsdnFrame extends JFrame{
- public HelloCsdnFrame()
- {
- setTitle("Hello CSDN.NET");
- setSize(WIDTH,HEIGHT);
- HelloCsdnPanel panel=new HelloCsdnPanel();
- Container c=getContentPane();
- c.add(panel);
- }
- public static final int WIDTH=300;
- public static final int HEIGHT=200;
- }
- //第三部分
- class HelloCsdnPanel extends JPanel{
- public void paintComponent(Graphics g){
- super.paintComponent(g);
- g.drawString("Hello CSDN.NET",MESSAGE_X,MESSAGE_Y);
- }
- public static final int MESSAGE_X=100;
- public static final int MESSAGE_Y=100;
- }
复制代码 |