import javax.swing.*;
import java.awt.*;
/**
* @version 1.33 2015-05-12
* @author Cay Horstmann
*/
public class NotHelloWorld
{
public static void main(String[] args)
{
EventQueue.invokeLater(() ->
{
JFrame frame =
new NotHelloWorldFrame();
frame.setTitle(
"NotHelloWorld");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(
true);
});
}
}
/**
* A frame that contains a message panel
*/
class NotHelloWorldFrame extends JFrame
{
public NotHelloWorldFrame()
{
add(
new NotHelloWorldComponent());
pack();
}
}
/**
* A component that displays a message.
*/
class NotHelloWorldComponent extends JComponent
{
public static final int MESSAGE_X =
75;
public static final int MESSAGE_Y =
100;
private static final int DEFAULT_WIDTH =
300;
private static final int DEFAULT_HEIGHT =
200;
public void paintComponent(Graphics g)
{
g.drawString(
"Not a Hello, World program", MESSAGE_X, MESSAGE_Y);
}
public Dimension
getPreferredSize() {
return new Dimension(DEFAULT_WIDTH, DEFAULT_HEIGHT); }
}
转载请注明原文地址: https://ju.6miu.com/read-969941.html