//在面板上显示一条信息
import javax.swing.*;
import java.awt.*;
//import java.awt.event.*;
import java.awt.geom.*;
public class SimpleFrameTest
{
public static void main(String[] args)
{
SimpleFrame frame = new SimpleFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
} //框架类
class SimpleFrame extends JFrame
{
public SimpleFrame()
{
setTitle("This is a Title");
setSize(WIDTH,HEIGHT);
//加入一个面板到框架
HelloPanel panel = new HelloPanel ();
Container contentPane = getContentPane();
contentPane.add(panel);
}
public static final int WIDTH = 400;
public static final int HEIGHT = 400;
}
import javax.swing.*;
import java.awt.*;
//import java.awt.event.*;
import java.awt.geom.*;
public class SimpleFrameTest
{
public static void main(String[] args)
{
SimpleFrame frame = new SimpleFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
} //框架类
class SimpleFrame extends JFrame
{
public SimpleFrame()
{
setTitle("This is a Title");
setSize(WIDTH,HEIGHT);
//加入一个面板到框架
HelloPanel panel = new HelloPanel ();
Container contentPane = getContentPane();
contentPane.add(panel);
}
public static final int WIDTH = 400;
public static final int HEIGHT = 400;
}
import java.awt.*;
//import java.awt.event.*;
import java.awt.geom.*;
public class SimpleFrameTest
{
public static void main(String[] args)
{
SimpleFrame frame = new SimpleFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
} //框架类
class SimpleFrame extends JFrame
{
public SimpleFrame() {
setTitle("This is a Title");
setSize(WIDTH,HEIGHT);
//加入一个面板到框架
HelloPanel panel =
new HelloPanel("Hello this is message", 100, 100);
Container contentPane = getContentPane();
contentPane.add(panel);
} class HelloPanel extends JPanel{
String msg = null;
int MESSAGE_X, MESSAGE_Y; HelloPanel(String msg, int x, int y){
super();
this.msg = msg;
MESSAGE_X = x;
MESSAGE_Y = y;
}
public void paint(Graphics g){
g.drawString(msg, MESSAGE_X, MESSAGE_Y);
}
} public static final int WIDTH = 400;
public static final int HEIGHT = 400;
}