myapplication.java
来自「教给你如何将JavaApplet程序转化为JavaApplication程序的一」· Java 代码 · 共 67 行
JAVA
67 行
// written by : Christine Amarra
// December 15, 2004
//To use swing and graphics components
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
//public class MyApplet extends JApplet
public class MyApplication extends JFrame
{
private DrawingCanvas canvas = null;
private JButton button = null;
//the main method needed for the application
public static void main(String args[])
{
MyApplication frame = new MyApplication();
frame.show();
}
public MyApplication()
{
this.init(); //calling init()
//frame-specific calls
this.setSize(450,450); //you have to set the size of the frame
this.setTitle("MyApplication");
this.addWindowListener(new WindowAdapter()
{
//anonymous inner class for WindowAdapter
public void windowClosing( WindowEvent we )
{
System.exit(0);
}
});
}
//initialize components here
public void init()
{
Container c = this.getContentPane();
button = new JButton("Click Me");
c.add(button, "North");
//The old way of doing action listeners on buttons...
//button.addActionListener(this);
//Don't forget to define actionPerformed();
//The new way of doing action listeners on buttons...
button.addActionListener( new ActionListener()
{
//anonymous inner class for WindowAdapter
public void actionPerformed( ActionEvent ae )
{
System.out.println("Clicked!");
}
});
//we'll be discussing more on this next year... :)
canvas = new DrawingCanvas();
c.add(canvas);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?