importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;publicclassBuju2extendsJFrameimplementsActionListener{JButtonjb1=newJButton("你");JButtonjb2=newJButt...
import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class Buju2 extends JFrame implements ActionListener { JButton jb1=new JButton("你"); JButton jb2=new JButton("是"); JButton jb3=new JButton("坏"); JButton jb4=new JButton("蛋"); JLabel jl=new JLabel("白痴"); Image i=this.getToolkit().getImage("C:\\Windows\\Web\\Wallpaper\\Windows\\img0.jpg"); //你的图片路径 JPanel jp=new JPanel(); public Buju2(){ jl.setVerticalAlignment(JLabel.CENTER); jl.setHorizontalAlignment(JLabel.CENTER); this.setTitle("好蛋疼"); jp.setLayout(new BorderLayout()); jb1.addActionListener(this); jb2.addActionListener(this); jb3.addActionListener(this); jb4.addActionListener(this); jp.add(jb1,BorderLayout.NORTH); jp.add(jb2,BorderLayout.SOUTH); jp.add(jb3,BorderLayout.EAST); jp.add(jb4,BorderLayout.WEST); jp.add(jl,BorderLayout.CENTER); this.add(jp); this.setBounds(300,250,300,200); this.setVisible(true); } public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if(e.getSource()==jb1){ jl.setText("你"); } else if(e.getSource()==jb2){ jl.setText("是"); } else if(e.getSource()==jb3){ jl.setText("坏"); } else if(e.getSource()==jb4){ jl.setText("蛋"); } } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Buju2 b=new Buju2(); } }
展开