DefaultFrame.java~11~
上传用户:qiye11114
上传日期:2010-01-20
资源大小:126k
文件大小:4k
源码类别:

其他智力游戏

开发平台:

Java

  1. package hanoi;
  2. import java.awt.BorderLayout;
  3. import java.awt.Dimension;
  4. import javax.swing.JFrame;
  5. import javax.swing.JPanel;
  6. import java.awt.Label;
  7. import java.awt.*;
  8. import javax.swing.JComboBox;
  9. import javax.swing.JButton;
  10. import javax.swing.JLabel;
  11. import java.awt.event.ActionEvent;
  12. import java.awt.event.ActionListener;
  13. import javax.swing.*;
  14. /**
  15.  * <p>Title: Hanoi Pan</p>
  16.  *
  17.  * <p>Description: </p>
  18.  *
  19.  * <p>Copyright: Copyright (c) 2005</p>
  20.  *
  21.  * <p>Company: </p>
  22.  *
  23.  * @author ZhangYuan
  24.  * @version 1.0
  25.  */
  26. public class DefaultFrame extends JFrame {
  27.     JPanel contentPane;
  28.     JComboBox jComboBox1 = new JComboBox();
  29.     JButton jButton1 = new JButton();
  30.     JButton jButton2 = new JButton();
  31.     JLabel jLabel1 = new JLabel();
  32.     public DefaultFrame() {
  33.         try {
  34.             setDefaultCloseOperation(EXIT_ON_CLOSE);
  35.             jbInit();
  36.         } catch (Exception exception) {
  37.             exception.printStackTrace();
  38.         }
  39.     }
  40.     /**
  41.      * Component initialization.
  42.      *
  43.      * @throws java.lang.Exception
  44.      */
  45.     private void jbInit() throws Exception {
  46.         contentPane = (JPanel) getContentPane();
  47.         contentPane.setLayout(null);
  48.         this.setResizable(false);
  49.         setSize(new Dimension(400, 300));
  50.         setTitle("Hanoi");
  51.         jComboBox1.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
  52.         jComboBox1.setBorder(BorderFactory.createEtchedBorder());
  53.         jComboBox1.setBounds(new Rectangle(139, 177, 102, 26));
  54.         jComboBox1.addItem("1层");
  55.         jComboBox1.addItem("2层");
  56.         jComboBox1.addItem("3层");
  57.         jComboBox1.addItem("4层");
  58.         jComboBox1.addItem("5层");
  59.         jComboBox1.addItem("6层");
  60.         jComboBox1.addItem("7层");
  61.         jComboBox1.addItem("8层");
  62.         jButton1.setBounds(new Rectangle(267, 175, 71, 27));
  63.         jButton1.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
  64.         jButton1.setText("开始");
  65.         jButton1.addActionListener(new DefaultFrame_jButton1_actionAdapter(this));
  66.         jButton2.setBounds(new Rectangle(165, 217, 71, 27));
  67.         jButton2.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
  68.         jButton2.setText("退出");
  69.         jButton2.addActionListener(new DefaultFrame_jButton2_actionAdapter(this));
  70.         jLabel1.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
  71.         jLabel1.setToolTipText("");
  72.         jLabel1.setText("Hanoi 层数:");
  73.         jLabel1.setBounds(new Rectangle(34, 173, 79, 25));
  74.         contentPane.add(jLabel1);
  75.         contentPane.add(jComboBox1);
  76.         contentPane.add(jButton1);
  77.         contentPane.add(jButton2);
  78.     }
  79.     public void jButton2_actionPerformed(ActionEvent e) {
  80.         System.exit(0);
  81.     }
  82.     public void jButton1_actionPerformed(ActionEvent e) {
  83.         DrawingFrame myDrawingFrame = new DrawingFrame(this.jComboBox1.getSelectedIndex()+1);
  84.         myDrawingFrame.show();
  85.         this.dispose();
  86.     }
  87. }
  88. class DefaultFrame_jButton1_actionAdapter implements ActionListener {
  89.     private DefaultFrame adaptee;
  90.     DefaultFrame_jButton1_actionAdapter(DefaultFrame adaptee) {
  91.         this.adaptee = adaptee;
  92.     }
  93.     public void actionPerformed(ActionEvent e) {
  94.         adaptee.jButton1_actionPerformed(e);
  95.     }
  96. }
  97. class DefaultFrame_jButton2_actionAdapter implements ActionListener {
  98.     private DefaultFrame adaptee;
  99.     DefaultFrame_jButton2_actionAdapter(DefaultFrame adaptee) {
  100.         this.adaptee = adaptee;
  101.     }
  102.     public void actionPerformed(ActionEvent e) {
  103.         adaptee.jButton2_actionPerformed(e);
  104.     }
  105. }