Java Programming: JButton Final Programming
2013-08-23 21:15
281 查看
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class Gui extends JFrame{
private JButton reg;
private JButton custom;
public Gui(){
super("The title");
setLayout(new FlowLayout());
reg = new JButton("reg button");
add(reg);
Icon b = new ImageIcon(getClass().getResource("1111.png"));
Icon x = new ImageIcon(getClass().getResource("222.png"));
custom = new JButton("Custom", b);
custom.setRolloverIcon(x);
add(custom);
HandlerClass handler = new HandlerClass();
reg.addActionListener(handler);
custom.addActionListener(handler);
}
private class HandlerClass implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
JOptionPane.showMessageDialog(null, String.format("%s", e.getActionCommand()));
if (e.getSource() == reg) {
}
}
}
}
import javax.swing.JFrame;
public class Main {
public static void main(String[] args){
Gui go = new Gui();
go.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
go.setSize(300, 200);
go.setVisible(true);
}
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class Gui extends JFrame{
private JButton reg;
private JButton custom;
public Gui(){
super("The title");
setLayout(new FlowLayout());
reg = new JButton("reg button");
add(reg);
Icon b = new ImageIcon(getClass().getResource("1111.png"));
Icon x = new ImageIcon(getClass().getResource("222.png"));
custom = new JButton("Custom", b);
custom.setRolloverIcon(x);
add(custom);
HandlerClass handler = new HandlerClass();
reg.addActionListener(handler);
custom.addActionListener(handler);
}
private class HandlerClass implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
JOptionPane.showMessageDialog(null, String.format("%s", e.getActionCommand()));
if (e.getSource() == reg) {
}
}
}
}
import javax.swing.JFrame;
public class Main {
public static void main(String[] args){
Gui go = new Gui();
go.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
go.setSize(300, 200);
go.setVisible(true);
}
}
相关文章推荐
- 2017 China Collegiate Programming Contest Final (CCPC 2017)
- The 15th UESTC Programming Contest Final 总结
- Benelux Algorithm Programming Contest Final-B解题报告
- 2016-2017 ACM Central Region of Russia Quarterfinal Programming Contest
- The 14th UESTC Programming Contest Final B - Banana Watch 预处理、前缀和
- Sichuan University Programming Contest 2013 Final (singal)E题
- The 10th UESTC Programming Contest Final 总结
- Gym 101243 (2016-2017 ACM Central Region of Russia Quarterfinal Programming Contest)
- Sichuan University Programming Contest 2013 Final (Single)F题
- The 14th UESTC Programming Contest Final Warmup D - Cube
- The 14th UESTC Programming Contest Final B - Banana Watch 预处理、前缀和
- The 9th UESTC Programming Contest Final——Easy Problem
- The 10th UESTC Programming Contest Final [D hours]
- Head First Programming - hlmix.py(final)
- Sichuan University Programming Contest 2013 Final (Single)C题
- The 14th UESTC Programming Contest Final I - Intersection 计算几何、积分、精度
- Java Programming: the Final Check Box Programming
- JAVA面试题解惑系列(四)——final、finally和finalize的区别
- 黑马程序员_staic,final用法总结
- JAVA第七节-继承,继承中方法重写,继承的初始化顺序,final关键字,super关键字,object类