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

📄 savedialog.java

📁 该文件中包含有源代码及一部分的文档,该系统是一个小型的英语单词字典的系统.
💻 JAVA
字号:
package english;

import java.awt.*;
import javax.swing.*;
import com.borland.jbcl.layout.PaneLayout;
import com.borland.jbcl.layout.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Box;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2007</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class SaveDialog extends JDialog {
    JPanel panel1 = new JPanel();
    JPanel jPanel1 = new JPanel();
    JPanel jPanel2 = new JPanel();
    JPanel jPanel3 = new JPanel();
    JPanel jPanel4 = new JPanel();
    JLabel jLabel1 = new JLabel();
    PaneLayout paneLayout1 = new PaneLayout();
    JTextField jTextField1 = new JTextField();
    FlowLayout flowLayout1 = new FlowLayout();
    JRadioButton jRadioButton1 = new JRadioButton();
    JRadioButton jRadioButton2 = new JRadioButton();
    JButton jButton1 = new JButton();
    JButton jButton2 = new JButton();
    ButtonGroup buttongroup = new ButtonGroup();
    String operate = "";
    String content = "";
    BoxLayout2 boxLayout21 = new BoxLayout2();
    JPanel jPanel5 = new JPanel();
    JPanel jPanel6 = new JPanel();
    Frame1 frame;

    public SaveDialog(String operate,String content,Frame1 frame) {
        super(new Frame(),"保存",true);
        this.operate = operate;
        this.content = content;
        this.frame = frame;
        try {
            setDefaultCloseOperation(DISPOSE_ON_CLOSE);
            jbInit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    private void jbInit() throws Exception {
        panel1.setLayout(new BoxLayout(panel1,BoxLayout.PAGE_AXIS));
        jLabel1.setText("   请输入标题:");
        jPanel1.setLayout(paneLayout1);
        jPanel2.setLayout(flowLayout1);
        jTextField1.setColumns(33);
        jRadioButton1.setSelected(true);
        jRadioButton1.setText("日常口语");
        jRadioButton2.setText("复杂口语");
        jButton1.setText("取消");
        jButton1.addActionListener(new SaveDialog_jButton1_actionAdapter(this));
        jButton2.setText("保存");
        jButton2.addActionListener(new SaveDialog_jButton2_actionAdapter(this));
        jPanel3.setLayout(boxLayout21);
        getContentPane().add(panel1);
        buttongroup.add(jRadioButton1);
        buttongroup.add(jRadioButton2);
        jPanel4.add(jButton2);
        jPanel4.add(jButton1);
        jPanel1.add(jLabel1,
                    new PaneConstraints("jLabel1", "jLabel1",
                                        PaneConstraints.ROOT, 1.0F));
        jPanel2.add(jTextField1, null);
        panel1.add(Box.createRigidArea(new Dimension(0,10)));
        jPanel3.add(jPanel6);
        jPanel6.add(jRadioButton1);
        jPanel3.add(jPanel5);
        jPanel5.add(jRadioButton2);
        panel1.add(jPanel1);
        panel1.add(jPanel2);
        panel1.add(jPanel3);
        panel1.add(jPanel4);
        panel1.add(Box.createRigidArea(new Dimension(0,10)));
        if(operate.equals("口语练习")){
            this.pack();
            this.setSize(254,165);
            this.centerdialog();
        } else if(operate.equals("成语故事")){
            panel1.remove(jPanel3);
            this.pack();
            this.setSize(254,155);
            this.centerdialog();
        } else if(operate.equals("词语接龙")){
            panel1.remove(jPanel3);
            this.pack();
            this.setSize(254,155);
            this.centerdialog();
        } else if(operate.equals("歌曲点播")){
            jRadioButton1.setText("boy");
            jRadioButton2.setText("girl");
            this.pack();
            this.setSize(254,165);
            this.centerdialog();
        }
    }

    public void centerdialog(){
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
         Dimension frameSize = this.getSize();
         if (frameSize.height > screenSize.height) {
             frameSize.height = screenSize.height;
         }
         if (frameSize.width > screenSize.width) {
             frameSize.width = screenSize.width;
         }
         this.setLocation((screenSize.width - frameSize.width) / 2,
                           (screenSize.height - frameSize.height) / 2);
    }

    public void jButton1_actionPerformed(ActionEvent e) {
        this.setVisible(false);
    }

    public void jButton2_actionPerformed(ActionEvent e) {
        if(operate.equals("口语练习")){
            this.savespokenlanguage();
            frame.jPanel6.repainttree();
        } else if(operate.equals("成语故事")){
            this.savestory();
            frame.jPanel8.repainttree();
        } else if(operate.equals("词语接龙")){
            this.saveconword();
            frame.jPanel10.repainttree();
        } else if(operate.equals("歌曲点播")){
            this.savemusic();
            frame.jPanel12.repainttree();
        }
    }

    public void savespokenlanguage(){
        String title = jTextField1.getText().trim();
        if(title.equals("")){
          JOptionPane.showMessageDialog(this,"对不起,标题不可为空!");
          return;
        }
        String type = jRadioButton1.isSelected()?"simple":"hard";
        String sql = "insert into spokenlanguage values('"+title+"','"+content+"','"+type+"')";
        this.update(sql);
    }

    public void savestory(){
        String title = jTextField1.getText().trim();
        if(title.equals("")){
          JOptionPane.showMessageDialog(this,"对不起,标题不可为空!");
          return;
        }
        String sql = "insert into idiom_story values('"+title+"','"+content+"')";
        this.update(sql);
    }

    public void saveconword(){
       String title = jTextField1.getText().trim();
       if(title.equals("")){
         JOptionPane.showMessageDialog(this,"对不起,标题不可为空!");
         return;
       }
       String sql = "insert into head_to_tail_word values('"+title+"','"+content+"')";
       this.update(sql);
    }

    public void savemusic(){
        String title = jTextField1.getText().trim();
        if(title.equals("")){
          JOptionPane.showMessageDialog(this,"对不起,标题不可为空!");
          return;
        }
        String sex = jRadioButton1.isSelected()?"simple":"hard";
        String sql = "insert into music values('"+title+"','"+content+"','"+sex+"')";
        this.update(sql);
    }

    public void update(String sql){
       Database db = new Database();
       if(db.update(sql)){
           JOptionPane.showMessageDialog(this,"保存成功!");
           this.setVisible(false);
       } else {
           JOptionPane.showMessageDialog(this,"保存失败,请重试!");
       }
    }
}


class SaveDialog_jButton2_actionAdapter implements ActionListener {
    private SaveDialog adaptee;
    SaveDialog_jButton2_actionAdapter(SaveDialog adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jButton2_actionPerformed(e);
    }
}


class SaveDialog_jButton1_actionAdapter implements ActionListener {
    private SaveDialog adaptee;
    SaveDialog_jButton1_actionAdapter(SaveDialog adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jButton1_actionPerformed(e);
    }
}

⌨️ 快捷键说明

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