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

📄 addnewvideodialog.java

📁 本人写的一个简单VCD租赁系统
💻 JAVA
字号:
//************************************************//AddNewVideoDialog.java//This class is used to create an GUI dialog for//adding new videos to the stock.//Created by Xiaobin Lin               3/Dec/2004//************************************************package Main;import javax.swing.*;import javax.swing.WindowConstants;import javax.swing.text.*;import java.awt.*;import java.awt.event.*;import java.text.*;public class AddNewVideoDialog extends JDialog {        //Constructor: automatically invoked when a new instance of AddNewVideoDialog is created    public AddNewVideoDialog(Frame parent, boolean modal, VideoSet vSet) {        super(parent, modal);        videoSet = vSet;        initComponents();    }        // This method is called from within the constructor to    // initialize the GUI for the add-new-video dialog.    private void initComponents() {        panelMessage = new JPanel();        textAreaStep = new JTextArea();        labelSteps = new JLabel();        labelNotes = new JLabel();        textAreaNotes = new JTextArea();        panelFileds = new JPanel();        labelClassNo = new JLabel();        labelTitle = new JLabel();        labelDirector = new JLabel();        labelLangClass = new JLabel();        labelSpecificLang = new JLabel();        comboBoxLangClass = new JComboBox();        textFieldTitle = new JTextField();        textFieldDirector = new JTextField();        textFieldSpecificLang = new JTextField();        formattedTextFieldClassNo = new JFormattedTextField(createFormatter("#####"));        buttonAdd = new JButton();        buttonCancel = new JButton();        getContentPane().setLayout(null);        setDefaultCloseOperation(DISPOSE_ON_CLOSE);        setTitle("Add a New Video");        setModal(true);        setName("dialogAddNewVideo");        setResizable(false);        panelMessage.setLayout(null);        panelMessage.setFont(new Font("Times New Roman", 0, 12));        textAreaStep.setEditable(false);        textAreaStep.setFont(new Font("Times New Roman", 1, 12));        textAreaStep.setText("Fill in all the fields on\nthe right-hand side then\nclick the \"Add\" button to\nadd a new video.");        textAreaStep.setFocusable(false);        textAreaStep.setOpaque(false);        panelMessage.add(textAreaStep);        textAreaStep.setBounds(10, 40, 160, 60);        labelSteps.setFont(new Font("Times New Roman", 1, 14));        labelSteps.setText("Steps");        panelMessage.add(labelSteps);        labelSteps.setBounds(10, 10, 60, 20);        labelNotes.setFont(new Font("Times New Roman", 1, 14));        labelNotes.setText("Notes");        panelMessage.add(labelNotes);        labelNotes.setBounds(10, 200, 40, 20);        textAreaNotes.setEditable(false);        textAreaNotes.setFont(new Font("Times New Roman", 1, 12));        textAreaNotes.setText("The \"Class #\" field can only \nbe a 5-digit integer.");        textAreaNotes.setFocusable(false);        textAreaNotes.setOpaque(false);        panelMessage.add(textAreaNotes);        textAreaNotes.setBounds(10, 230, 160, 40);        getContentPane().add(panelMessage);        panelMessage.setBounds(0, 0, 180, 330);        panelFileds.setLayout(null);        labelClassNo.setFont(new Font("Times New Roman", 1, 12));        labelClassNo.setHorizontalAlignment(SwingConstants.TRAILING);        labelClassNo.setText("Class #:");        panelFileds.add(labelClassNo);        labelClassNo.setBounds(70, 20, 50, 20);        labelTitle.setFont(new Font("Times New Roman", 1, 12));        labelTitle.setHorizontalAlignment(SwingConstants.TRAILING);        labelTitle.setText("Title:");        panelFileds.add(labelTitle);        labelTitle.setBounds(80, 80, 40, 20);        labelDirector.setFont(new Font("Times New Roman", 1, 12));        labelDirector.setHorizontalAlignment(SwingConstants.TRAILING);        labelDirector.setText("Director:");        panelFileds.add(labelDirector);        labelDirector.setBounds(60, 140, 60, 20);        labelLangClass.setFont(new Font("Times New Roman", 1, 12));        labelLangClass.setHorizontalAlignment(SwingConstants.TRAILING);        labelLangClass.setText("Lang Class:");        panelFileds.add(labelLangClass);        labelLangClass.setBounds(50, 200, 70, 20);        labelSpecificLang.setFont(new Font("Times New Roman", 1, 12));        labelSpecificLang.setHorizontalAlignment(SwingConstants.TRAILING);        labelSpecificLang.setText("Specific Language:");        panelFileds.add(labelSpecificLang);        labelSpecificLang.setBounds(10, 260, 110, 20);        comboBoxLangClass.setFont(new Font("Times New Roman", 0, 12));        comboBoxLangClass.setModel(new DefaultComboBoxModel(new String[] { "1", "2" }));        panelFileds.add(comboBoxLangClass);        comboBoxLangClass.setBounds(140, 200, 100, 22);        textFieldTitle.setFont(new Font("Times New Roman", 0, 12));        panelFileds.add(textFieldTitle);        textFieldTitle.setBounds(140, 80, 210, 19);        textFieldDirector.setFont(new Font("Times New Roman", 0, 12));        panelFileds.add(textFieldDirector);        textFieldDirector.setBounds(140, 140, 140, 19);        textFieldSpecificLang.setFont(new Font("Times New Roman", 0, 12));        panelFileds.add(textFieldSpecificLang);        textFieldSpecificLang.setBounds(140, 260, 100, 19);        formattedTextFieldClassNo.setText("10000");        formattedTextFieldClassNo.setFont(new Font("Times New Roman", 0, 12));        panelFileds.add(formattedTextFieldClassNo);        formattedTextFieldClassNo.setBounds(140, 20, 50, 19);        getContentPane().add(panelFileds);        panelFileds.setBounds(180, 0, 370, 330);        buttonAdd.setFont(new Font("Times New Roman", 0, 12));        buttonAdd.setText("Add");        buttonAdd.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent evt) {                buttonAddActionPerformed(evt);            }        });        getContentPane().add(buttonAdd);        buttonAdd.setBounds(380, 350, 80, 23);        buttonCancel.setFont(new Font("Times New Roman", 0, 12));        buttonCancel.setText("Cancel");        buttonCancel.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent evt) {                buttonCancelActionPerformed(evt);            }        });        getContentPane().add(buttonCancel);        buttonCancel.setBounds(470, 350, 80, 23);        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();        setBounds((screenSize.width-570)/2, (screenSize.height-420)/2, 570, 420);    }//The end of initialization of components    //A method for creating a MaskFormatter, this is used to format formattedTextFieldClassNo    //to make it only accept a 5-digit integer    protected MaskFormatter createFormatter(String s) {        MaskFormatter formatter = null;        try {            formatter = new MaskFormatter(s);        } catch (ParseException exc) {            System.err.println("formatter is bad: " + exc.getMessage());            System.exit(-1);        }        return formatter;    }        //when add button is pressed    private void buttonAddActionPerformed(ActionEvent evt) {        videoClassNo = Integer.parseInt(formattedTextFieldClassNo.getText());        videoTitle = textFieldTitle.getText();        videoDirector = textFieldDirector.getText();        videoLangClass = Integer.parseInt((String)comboBoxLangClass.getSelectedItem());        videoSpecificLang = textFieldSpecificLang.getText();        Video video = new Video(videoClassNo, videoTitle, videoDirector, videoLangClass, videoSpecificLang);        videoSet.addNewVideo(video);        exitDialog();    }    //When cancel button is pressed    private void buttonCancelActionPerformed(ActionEvent evt) {        exitDialog();    }        //close dialog    private void exitDialog(){        setVisible(false);        dispose();            }               //Variables declaration - GUI-related    private JButton buttonAdd;    private JButton buttonCancel;    private JComboBox comboBoxLangClass;    private JFormattedTextField formattedTextFieldClassNo;    private JLabel labelClassNo;    private JLabel labelDirector;    private JLabel labelLangClass;    private JLabel labelNotes;    private JLabel labelSpecificLang;    private JLabel labelSteps;    private JLabel labelTitle;    private JPanel panelFileds;    private JPanel panelMessage;    private JTextArea textAreaNotes;    private JTextArea textAreaStep;    private JTextField textFieldDirector;    private JTextField textFieldSpecificLang;    private JTextField textFieldTitle;    //variables declaration - non-GUI-related    private VideoSet videoSet;    private int videoClassNo;    private String videoTitle;    private String videoDirector;    private int videoLangClass;    private String videoSpecificLang;    }

⌨️ 快捷键说明

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