📄 myapplication.java
字号:
// 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -