DefaultFrame.java~11~
资源名称:汉诺塔图形演示.rar [点击查看]
上传用户:qiye11114
上传日期:2010-01-20
资源大小:126k
文件大小:4k
源码类别:
其他智力游戏
开发平台:
Java
- package hanoi;
- import java.awt.BorderLayout;
- import java.awt.Dimension;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import java.awt.Label;
- import java.awt.*;
- import javax.swing.JComboBox;
- import javax.swing.JButton;
- import javax.swing.JLabel;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.*;
- /**
- * <p>Title: Hanoi Pan</p>
- *
- * <p>Description: </p>
- *
- * <p>Copyright: Copyright (c) 2005</p>
- *
- * <p>Company: </p>
- *
- * @author ZhangYuan
- * @version 1.0
- */
- public class DefaultFrame extends JFrame {
- JPanel contentPane;
- JComboBox jComboBox1 = new JComboBox();
- JButton jButton1 = new JButton();
- JButton jButton2 = new JButton();
- JLabel jLabel1 = new JLabel();
- public DefaultFrame() {
- try {
- setDefaultCloseOperation(EXIT_ON_CLOSE);
- jbInit();
- } catch (Exception exception) {
- exception.printStackTrace();
- }
- }
- /**
- * Component initialization.
- *
- * @throws java.lang.Exception
- */
- private void jbInit() throws Exception {
- contentPane = (JPanel) getContentPane();
- contentPane.setLayout(null);
- this.setResizable(false);
- setSize(new Dimension(400, 300));
- setTitle("Hanoi");
- jComboBox1.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
- jComboBox1.setBorder(BorderFactory.createEtchedBorder());
- jComboBox1.setBounds(new Rectangle(139, 177, 102, 26));
- jComboBox1.addItem("1层");
- jComboBox1.addItem("2层");
- jComboBox1.addItem("3层");
- jComboBox1.addItem("4层");
- jComboBox1.addItem("5层");
- jComboBox1.addItem("6层");
- jComboBox1.addItem("7层");
- jComboBox1.addItem("8层");
- jButton1.setBounds(new Rectangle(267, 175, 71, 27));
- jButton1.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
- jButton1.setText("开始");
- jButton1.addActionListener(new DefaultFrame_jButton1_actionAdapter(this));
- jButton2.setBounds(new Rectangle(165, 217, 71, 27));
- jButton2.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
- jButton2.setText("退出");
- jButton2.addActionListener(new DefaultFrame_jButton2_actionAdapter(this));
- jLabel1.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
- jLabel1.setToolTipText("");
- jLabel1.setText("Hanoi 层数:");
- jLabel1.setBounds(new Rectangle(34, 173, 79, 25));
- contentPane.add(jLabel1);
- contentPane.add(jComboBox1);
- contentPane.add(jButton1);
- contentPane.add(jButton2);
- }
- public void jButton2_actionPerformed(ActionEvent e) {
- System.exit(0);
- }
- public void jButton1_actionPerformed(ActionEvent e) {
- DrawingFrame myDrawingFrame = new DrawingFrame(this.jComboBox1.getSelectedIndex()+1);
- myDrawingFrame.show();
- this.dispose();
- }
- }
- class DefaultFrame_jButton1_actionAdapter implements ActionListener {
- private DefaultFrame adaptee;
- DefaultFrame_jButton1_actionAdapter(DefaultFrame adaptee) {
- this.adaptee = adaptee;
- }
- public void actionPerformed(ActionEvent e) {
- adaptee.jButton1_actionPerformed(e);
- }
- }
- class DefaultFrame_jButton2_actionAdapter implements ActionListener {
- private DefaultFrame adaptee;
- DefaultFrame_jButton2_actionAdapter(DefaultFrame adaptee) {
- this.adaptee = adaptee;
- }
- public void actionPerformed(ActionEvent e) {
- adaptee.jButton2_actionPerformed(e);
- }
- }