⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usingswingframe.java~67~

📁 JBuilder9 精髓 source code1.rar
💻 JAVA~67~
字号:
package usingswing;import java.awt.*;import java.awt.event.*;import javax.swing.*;import com.borland.jbcl.layout.*;import javax.swing.border.*;import javax.swing.event.*;public class usingSwingFrame extends JFrame {  private JPanel contentPane;  private BorderLayout borderLayout1 = new BorderLayout();  private JTabbedPane jTabbedPane1 = new JTabbedPane();  private JPanel jPanel1 = new JPanel();  private JPanel jPanel2 = new JPanel();  private JPanel jPanel3 = new JPanel();  private JPanel jPanel4 = new JPanel();  private XYLayout xYLayout1 = new XYLayout();  private JButton jButton1 = new JButton();  private JLabel jLabel1 = new JLabel();  private JToggleButton jToggleButton1 = new JToggleButton();  private JButton jButton2 = new JButton();  private JToggleButton jToggleButton2 = new JToggleButton();  private Border border1;  private TitledBorder titledBorder1;  private XYLayout xYLayout4 = new XYLayout();  private BorderLayout borderLayout2 = new BorderLayout();  private JPanel jPanel5 = new JPanel();  private JPanel jPanel6 = new JPanel();  private BorderLayout borderLayout3 = new BorderLayout();  private JPanel jPanel7 = new JPanel();  private BoxLayout2 boxLayout21 = new BoxLayout2();  private JPanel jPanel8 = new JPanel();  private JRadioButton jRadioButton1 = new JRadioButton();  private JRadioButton jRadioButton2 = new JRadioButton();  private VerticalFlowLayout verticalFlowLayout1 = new VerticalFlowLayout();  private VerticalFlowLayout verticalFlowLayout2 = new VerticalFlowLayout();  private JCheckBox jCheckBox3 = new JCheckBox();  private JCheckBox jCheckBox4 = new JCheckBox();  private JCheckBox jCheckBox5 = new JCheckBox();  private JRadioButton jRadioButton3 = new JRadioButton();  private JRadioButton jRadioButton4 = new JRadioButton();  private JCheckBox jCheckBox6 = new JCheckBox();  private JRadioButton jRadioButton5 = new JRadioButton();  private JLabel jLabel2 = new JLabel();  private ButtonGroup buttonGroup1 = new ButtonGroup();  private BorderLayout borderLayout4 = new BorderLayout();  private JTextField jTextField1 = new JTextField();  private JTextArea jTextArea1 = new JTextArea();  private String[] data = {"白菜", "萝卜", "黄瓜", "茄子","冬瓜","豆腐","西红柿","哈密瓜","鸡蛋"};  private JList jList1 = new JList(data);  private JLabel jLabel3 = new JLabel();  private Border border2;  private TitledBorder titledBorder2;  //Construct the frame  public usingSwingFrame() {    enableEvents(AWTEvent.WINDOW_EVENT_MASK);    try {      jbInit();    }    catch(Exception e) {      e.printStackTrace();    }  }  //Component initialization  private void jbInit() throws Exception  {    //setIconImage(Toolkit.getDefaultToolkit().createImage(usingSwingFrame.class.getResource("[Your Icon]")));    contentPane = (JPanel) this.getContentPane();    border1 = BorderFactory.createEmptyBorder();    titledBorder1 = new TitledBorder(BorderFactory.createEmptyBorder(),"");    border2 = new EtchedBorder(EtchedBorder.RAISED,Color.white,new Color(178, 178, 178));    titledBorder2 = new TitledBorder(new EtchedBorder(EtchedBorder.RAISED,Color.white,new Color(178, 178, 178)),"列表框");    contentPane.setLayout(borderLayout1);    this.setSize(new Dimension(400, 300));    this.setTitle("使用Swing组件的Java应用系统");    jPanel1.setLayout(xYLayout1);    jButton1.setText("显示文字");    jButton1.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        jButton1_actionPerformed(e);      }    });    jToggleButton1.setText("文字颜色开关");    jToggleButton1.addChangeListener(new javax.swing.event.ChangeListener() {      public void stateChanged(ChangeEvent e) {        jToggleButton1_stateChanged(e);      }    });    jButton2.setText("隐藏文字");    jButton2.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        jButton2_actionPerformed(e);      }    });    jToggleButton2.setToolTipText("");    jToggleButton2.setText("文字大小开关");    jToggleButton2.addChangeListener(new javax.swing.event.ChangeListener() {      public void stateChanged(ChangeEvent e) {        jToggleButton2_stateChanged(e);      }    });    jPanel1.setToolTipText("");    jPanel3.setLayout(borderLayout4);    jPanel4.setLayout(xYLayout4);    jPanel2.setLayout(borderLayout2);    jPanel6.setLayout(borderLayout3);    jPanel5.setLayout(boxLayout21);    jPanel7.setLayout(verticalFlowLayout1);    jRadioButton1.setText("早上好,朋友!");    jRadioButton1.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        jRadioButton1_actionPerformed(e);      }    });    jRadioButton2.setText("再见,朋友!");    jRadioButton2.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        jRadioButton2_actionPerformed(e);      }    });    jPanel8.setLayout(verticalFlowLayout2);    jCheckBox3.setText("设置背景颜色");    jCheckBox3.addChangeListener(new javax.swing.event.ChangeListener() {      public void stateChanged(ChangeEvent e) {        jCheckBox3_stateChanged(e);      }    });    jCheckBox4.setText("设置前景颜色");    jCheckBox4.addChangeListener(new javax.swing.event.ChangeListener() {      public void stateChanged(ChangeEvent e) {        jCheckBox4_stateChanged(e);      }    });    jCheckBox5.setText("设置字体为斜体");    jCheckBox5.addChangeListener(new javax.swing.event.ChangeListener() {      public void stateChanged(ChangeEvent e) {        jCheckBox5_stateChanged(e);      }    });    jRadioButton3.setText("中午好,朋友!");    jRadioButton3.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        jRadioButton3_actionPerformed(e);      }    });    jRadioButton4.setText("晚上好,朋友!");    jRadioButton4.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        jRadioButton4_actionPerformed(e);      }    });    jCheckBox6.setText("设置字体为大字");    jCheckBox6.addChangeListener(new javax.swing.event.ChangeListener() {      public void stateChanged(ChangeEvent e) {        jCheckBox6_stateChanged(e);      }    });    jRadioButton5.setText("你好啊,朋友!");    jRadioButton5.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        jRadioButton5_actionPerformed(e);      }    });    jLabel2.setBackground(Color.lightGray);    jPanel6.setBackground(Color.lightGray);    jTextField1.setText("请在此输入文字:");    jTextField1.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        jTextField1_actionPerformed(e);      }    });    jTextArea1.setEnabled(false);    jTextArea1.setEditable(false);    jList1.setBackground(Color.lightGray);    jList1.setBorder(titledBorder2);    jList1.setToolTipText("列表框");    jList1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);    jList1.addListSelectionListener(new javax.swing.event.ListSelectionListener() {      public void valueChanged(ListSelectionEvent e) {        jList1_valueChanged(e);      }    });    contentPane.add(jTabbedPane1,  BorderLayout.CENTER);    jTabbedPane1.add(jPanel1,   "按钮和开关演示");    jPanel1.add(jLabel1,  new XYConstraints(51, 139, 280, 52));    jPanel1.add(jToggleButton1,   new XYConstraints(51, 87, 120, 42));    jPanel1.add(jButton1,     new XYConstraints(51, 37, 121, 40));    jPanel1.add(jButton2, new XYConstraints(193, 37, 116, 40));    jPanel1.add(jToggleButton2,    new XYConstraints(193, 87, 117, 39));    jTabbedPane1.add(jPanel2,   "单选和多选按钮演示");    jPanel2.add(jPanel5, BorderLayout.CENTER);    jPanel2.add(jPanel6,  BorderLayout.SOUTH);    jPanel6.add(jLabel2, BorderLayout.NORTH);    jTabbedPane1.add(jPanel3,   "文字演示");    jPanel3.add(jTextField1, BorderLayout.NORTH);    jPanel3.add(jTextArea1, BorderLayout.CENTER);    jTabbedPane1.add(jPanel4,   "列表框演示");    jPanel4.add(jLabel3, new XYConstraints(13, 47, 124, 28));    jPanel4.add(jList1,          new XYConstraints(183, 13, 200, 213));    jPanel5.add(jPanel7, null);    jPanel7.add(jRadioButton5, null);    jPanel7.add(jRadioButton4, null);    jPanel7.add(jRadioButton3, null);    jPanel7.add(jRadioButton1, null);    jPanel7.add(jRadioButton2, null);    jPanel5.add(jPanel8, null);    jPanel8.add(jCheckBox6, null);    jPanel8.add(jCheckBox5, null);    jPanel8.add(jCheckBox4, null);    jPanel8.add(jCheckBox3, null);    buttonGroup1.add(jRadioButton4);    buttonGroup1.add(jRadioButton3);    buttonGroup1.add(jRadioButton1);    buttonGroup1.add(jRadioButton2);    buttonGroup1.add(jRadioButton5);  }  //Overridden so we can exit when window is closed  protected void processWindowEvent(WindowEvent e) {    super.processWindowEvent(e);    if (e.getID() == WindowEvent.WINDOW_CLOSING) {      System.exit(0);    }  }  void jButton1_actionPerformed(ActionEvent e) {   jLabel1.setText("我的文字演示");  }  void jButton2_actionPerformed(ActionEvent e) {   jLabel1.setText("");  }  void jToggleButton1_stateChanged(ChangeEvent e) {   if(jToggleButton1.isSelected())    jLabel1.setForeground(Color.blue);//选中时文字颜色为蓝色   else     jLabel1.setForeground(Color.red);//否则为红色 }  void jToggleButton2_stateChanged(ChangeEvent e) {    Font font1=new Font("宋体",Font.PLAIN,16);    Font font2=new Font("宋体",Font.PLAIN,24);    if(jToggleButton2.isSelected())     jLabel1.setFont(font2);//选中是字体为大字    else     jLabel1.setFont(font1);//否则为小号   }  void jRadioButton5_actionPerformed(ActionEvent e) {   jLabel2.setText("你好啊,朋友!");  }  void jRadioButton4_actionPerformed(ActionEvent e) {  jLabel2.setText("晚上好,朋友!");  }  void jRadioButton3_actionPerformed(ActionEvent e) {   jLabel2.setText("中午好,朋友!");  }  void jRadioButton1_actionPerformed(ActionEvent e) {    jLabel2.setText("早上好,朋友!");  }  void jRadioButton2_actionPerformed(ActionEvent e) {    jLabel2.setText("再见,朋友!");  }  void jCheckBox6_stateChanged(ChangeEvent e) {    update();  }  void jCheckBox5_stateChanged(ChangeEvent e) {     update();  }    void update()    {    Font font1=new Font("宋体",Font.PLAIN,12);    Font font2=new Font("宋体",Font.PLAIN,24);    Font font3=new Font("宋体",Font.ITALIC,12);    Font font4=new Font("宋体",Font.ITALIC,24);    if(jCheckBox6.isSelected()&&jCheckBox5.isSelected()){      jLabel2.setFont(font4);    }else if(jCheckBox6.isSelected()&&!jCheckBox5.isSelected())      {      jLabel2.setFont(font2);    }else if(!jCheckBox5.isSelected()&&!jCheckBox6.isSelected())    {      jLabel2.setFont(font1);    }else if(jCheckBox5.isSelected()&&!jCheckBox6.isSelected()){      jLabel2.setFont(font3);    }    }  void jCheckBox4_stateChanged(ChangeEvent e) {   if(jCheckBox4.isSelected())     jLabel2.setForeground(Color.red);     else     jLabel2.setForeground(Color.black);  }  void jCheckBox3_stateChanged(ChangeEvent e) {    if(jCheckBox3.isSelected())      jPanel6.setBackground(Color.blue);      else      jPanel6.setBackground(Color.lightGray);  }  void jTextField1_actionPerformed(ActionEvent e) {    jTextArea1.append(jTextField1.getText()+"\n");    jTextField1.setText("");  }  void jList1_valueChanged(ListSelectionEvent e) {  jLabel3.setText((String)jList1.getSelectedValue());  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -