swing13.java
来自「java 初学者学习实例」· Java 代码 · 共 38 行
JAVA
38 行
import javax. swing. *;
import java.awt.*;
import java. awt. event. *;
class TimeWin extends JFrame implements ActionListener
{static JTextArea text1, text2; Boy boy=new Boy();
JScrollPane scroll_1, scroll_2;Container con;
Timer time_1, time_2 ;
JSplitPane splitpane;
TimeWin ( )
{ super("有计数器的窗口");
time_1=new Timer(1000,this);
time_2=new Timer(2000,boy);
text1=new JTextArea (); text2=new JTextArea( );
scroll_1=new JScrollPane(text1);
scroll_2=new JScrollPane(text2);
splitpane=new JSplitPane (JSplitPane.HORIZONTAL_SPLIT, scroll_1,scroll_2);
setSize(200, 200);
setVisible (true);
con=getContentPane ( ); con. add (splitpane);
time_1.start () ;time_2.start ();
addWindowListener (new WindowAdapter ()
{public void windowClosing(WindowEvent e)
{System.exit(0);}});
}
public void actionPerformed(ActionEvent e)
{text1.append("欢迎光临"+"\n");}
}
class Boy implements ActionListener
{
public void actionPerformed(ActionEvent e)
{TimeWin.text2.append("再见!"+"\n");}
}
public class Swing13
{
public static void main(String args[])
{TimeWin win = new TimeWin();win.pack();}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?