swing8.java
来自「java 初学者学习实例」· Java 代码 · 共 38 行
JAVA
38 行
import javax.swing.*;import java.awt.*;import java.awt.event.*;
class Mywindow extends JFrame implements ActionListener
{JButton button1,button2,button3;JTextArea text;Icon icon;
Mywindow()
{setSize(200,200);setVisible(true);
Container con=getContentPane();
text = new JTextArea();
con.setLayout(new GridLayout(1,4));
icon = new ImageIcon("tom.jpg");
button1=new JButton("Boy", icon); button2=new JButton("Girl" ) ;
button3=new JButton("friend", new ImageIcon("jerry.jpg"));
button1.setVerticalTextPosition(AbstractButton. TOP);
button1.setMnemonic('b');
con.add(button1);con.add(button2);con.add(button3);con.add(text);
button1.addActionListener(this);button3.addActionListener(this);
addWindowListener(new WindowAdapter()
{public void windowClosing(WindowEvent e)
{System.exit(0);}});
}
public void actionPerformed(ActionEvent e)
{if(e.getSource()==button1)
{ text.setText(button1.getText()+button2.getText());
button2.setIcon(button1.getIcon());
button2.setHorizontalTextPosition(AbstractButton. RIGHT);
button3.setEnabled(false);
}
else if(e.getSource()==button3)
{ text.append(button3.getText( )); button2.setIcon(button3.getIcon());
}
}
}
public class Swing8
{ public static void main(String args[])
{ Mywindow win=new Mywindow();win.pack();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?