📄 sw2.java
字号:
/*
ImageIcon
Class
cons:
ImageIcon(String path)
*/
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class sw2 extends JFrame implements ActionListener
{
ImageIcon i1 = new ImageIcon("server.gif");
JButton b1 = new JButton("Ok",i1);
JButton b2 = new JButton("Cancel");
JPanel p1 = new JPanel(new FlowLayout(FlowLayout.LEFT));
public sw2()
{
Container con = getContentPane();
p1.add(b1);
p1.add(b2);
con.add(p1);
b1.addActionListener(this);
b2.addActionListener(this);
setSize(300,300);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == b1)
{
System.out.println("B1");
}
else
{
System.out.println("B2");
}
}
public static void main(String args[])
{
new sw2();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -