日期:2014-05-20 浏览次数:20809 次
package x; import java.awt.*; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.*; public class XDFrame1 extends JFrame { public static void main(String[] args) { XDFrame1 XDframe1= new XDFrame1(); XDframe1.showframe1(); } private JLabel label[] ; private JCheckBox checkBox; private ImageIcon imageIcon; private JTextArea textArea; public XDFrame1(){ super(); label=new JLabel[30]; checkBox=new JCheckBox(); imageIcon=new ImageIcon(); textArea=new JTextArea(); label[0]=new JLabel("A-Z "); label[1]=new JLabel("A"); label[2]=new JLabel("B"); label[3]=new JLabel("C"); label[4]=new JLabel("D"); label[5]=new JLabel("E"); label[6]=new JLabel("F"); label[7]=new JLabel("小写:"); label[8]=new JLabel("小写:"); label[9]=new JLabel("小写:"); label[10]=new JLabel("小写:"); label[11]=new JLabel("小写:"); label[12]=new JLabel("小写:"); label[13]=new JLabel("s"); label[14]=new JLabel("s"); label[15]=new JLabel("s"); label[16]=new JLabel("s"); label[17]=new JLabel("x"); label[18]=new JLabel("x"); label[19]=new JLabel("集合"); label[19].setFont(new Font("Serif",Font.PLAIN,36)); String Xushu="abcd"; textArea.setText(Xushu); imageIcon=new ImageIcon("images\\XueDao.jpg"); checkBox=new JCheckBox(imageIcon); } public void showframe1(){ this.setTitle("ABCD"); this.setSize(500, 500); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true); Container c=this.getContenPane(); JPanel panel1=new JPanel(); JPanel panel2=new JPanel(); panel1.setLayout(new BorderLayout()); panel2.setLayout(new GridLayout(8,3)); panel2.add(new JScrollPane(panel2)); panel1.add(label[19],"Center"); panel2.setLayout(new GridLayout(7,3)); panel2.add(label[0]); panel2.add(textArea); panel2.add(checkBox); panel2.add(label[1]); panel2.add(label[7]); panel2.add(label[13]); panel2.add(label[2]); panel2.add(label[8]); panel2.add(label[14]); panel2.add(label[3]); panel2.add(label[9]); panel2.add(label[15]); panel2.add(label[4]); panel2.add(label[10]); panel2.add(label[16]); panel2.add(label[5]); panel2.add(label[11]); panel2.add(label[17]); panel2.add(label[6]); panel2.add(label[12]); panel2.add(label[18]); this.add(panel1,"North"); this.add(panel1,"Center"); label[1].addMouseListener(new MyMouseClickListener()); label[2].addMouseListener(new MyMouseClickListener()); label[3].addMouseListener(new MyMouseClickListener()); label[4].addMouseListener(new MyMouseClickListener()); label[5].addMouseListener(new MyMouseClickListener()); label[6].addMouseListener(new MyMouseClickListener()); } class MyMouseClickListener extends MouseAdapter{ public void mousePressed(MouseEvent e){ if(e.getSource()==label[1]){ } } } }