border.java
来自「Java课程中所有的可运行程序 全部都是java课程中所涉及到的源码」· Java 代码 · 共 61 行
JAVA
61 行
import java.awt.*;
import java.awt.event.*;
public class border extends Frame{
Label txt=new Label("null");
Button bnorth=new Button("North");
Button bsouth=new Button("South");
Button beast=new Button("East");
Button bwest=new Button("West");
public border(String ss){
super(ss);
this.setLayout(new BorderLayout());
bnorth.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
processAction(e);}
} );
bsouth.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
processAction(e);}
} );
beast.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
processAction(e);}
} );
bwest.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
processAction(e);}
} );
add("North",bnorth);
add("South",bsouth);
add("East",beast);
add("West",bwest);
add("Center",txt);
}
public static void main(String[] args){
border nowframe=new border("BorderLayout");
nowframe.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
nowframe.pack();
nowframe.show();
}
public Dimension getPreferredSize()
{
return new Dimension(300,300);
}
public void processAction(ActionEvent e){
Object obj=e.getSource();
if(obj==bnorth) txt.setText("北");
if(obj==beast) txt.setText("东");
if(obj==bwest) txt.setText("西");
if(obj==bsouth) txt.setText("南");}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?