?? insertjdialog.java
字號:
/** Programmname : InsertJDialog <br>Klasse : <b> InsertJDialog </b>@autor Li,Haibin Hou,Yujing Zhang,Xiangpeng@version 1.0 / 15.12.2006*/import java.awt.*;import javax.swing.*;import java.awt.event.*;public class InsertJDialog extends JDialog{ private MainGUI parentJFrame; private Pkw insertPkw; private String identnummerString,typString,herstellerString, farbeString,kmleistungString,preisString; private int kmleistung,preis; private int errorcode; private JLabel insertJLabel; private JLabel identnummerJLabel,typJLabel,herstellerJLabel, farbeJLabel,kmleistungJLabel,preisJLabel; private JTextField identnummerJTextField,typJTextField, herstellerJTextField,farbeJTextField, kmleistungJTextField,preisJTextField; private JButton okJButton,clearJButton,quitJButton; private InsertJDialogActionListener aInsertJDialogActionListener; private static Font aFont=new Font("Courier",Font.BOLD,30); private static Font cFont=new Font("Courier",Font.BOLD,12); private static Color fColor=Color.white; private static Color editColor=Color.blue; private static Color noeditColor=Color.red; private static Color textColor=Color.white; private int pl=25,po=25,pw=170,ph=30; private int plbutton,pwbutton=100,pdelta=120; public InsertJDialog(MainGUI aGUI,boolean mode) { super(aGUI,mode); setSize(400,520); setLocation(100,10); getContentPane().setLayout(null); getContentPane().setBackground(fColor); aInsertJDialogActionListener = new InsertJDialogActionListener(this); insertJLabel=new JLabel("INSERT Pkw"); insertJLabel.setBounds(pl,po,2*pw,ph); insertJLabel.setFont(aFont); insertJLabel.setVisible(true); getContentPane().add(insertJLabel); identnummerJLabel=new JLabel("Identifikationsnr"); identnummerJLabel.setBounds(pl,po+=2*ph,pw,ph); identnummerJLabel.setFont(cFont); identnummerJLabel.setVisible(true); getContentPane().add(identnummerJLabel); identnummerJTextField=new JTextField(); identnummerJTextField.setBounds(pl+pw,po,pw,ph); identnummerJTextField.setFont(cFont); identnummerJTextField.setEditable(false); identnummerJTextField.setBackground(noeditColor); identnummerJTextField.setForeground(textColor); identnummerJTextField.setVisible(true); getContentPane().add(identnummerJTextField); typJLabel=new JLabel("Typ"); typJLabel.setBounds(pl,po+=2*ph,pw,ph); typJLabel.setFont(cFont); typJLabel.setVisible(true); getContentPane().add(typJLabel); typJTextField=new JTextField(); typJTextField.setBounds(pl+pw,po,pw,ph); typJTextField.setFont(cFont); typJTextField.setEditable(true); typJTextField.setBackground(editColor); typJTextField.setForeground(textColor); typJTextField.setVisible(true); getContentPane().add(typJTextField); herstellerJLabel=new JLabel("Hersteller"); herstellerJLabel.setBounds(pl,po+=2*ph,pw,ph); herstellerJLabel.setFont(cFont); herstellerJLabel.setVisible(true); getContentPane().add(herstellerJLabel); herstellerJTextField=new JTextField(); herstellerJTextField.setBounds(pl+pw,po,pw,ph); herstellerJTextField.setFont(cFont); herstellerJTextField.setEditable(true); herstellerJTextField.setBackground(editColor); herstellerJTextField.setForeground(textColor); herstellerJTextField.setVisible(true); getContentPane().add(herstellerJTextField); farbeJLabel=new JLabel("Farbe"); farbeJLabel.setBounds(pl,po+=2*ph,pw,ph); farbeJLabel.setFont(cFont); farbeJLabel.setVisible(true); getContentPane().add(farbeJLabel); farbeJTextField=new JTextField(); farbeJTextField.setBounds(pl+pw,po,pw,ph); farbeJTextField.setFont(cFont); farbeJTextField.setEditable(true); farbeJTextField.setBackground(editColor); farbeJTextField.setForeground(textColor); farbeJTextField.setVisible(true); getContentPane().add(farbeJTextField); kmleistungJLabel=new JLabel("Kilometerleistung"); kmleistungJLabel.setBounds(pl,po+=2*ph,pw,ph); kmleistungJLabel.setFont(cFont); kmleistungJLabel.setVisible(true); getContentPane().add(kmleistungJLabel); kmleistungJTextField=new JTextField(); kmleistungJTextField.setBounds(pl+pw,po,pw,ph); kmleistungJTextField.setFont(cFont); kmleistungJTextField.setEditable(true); kmleistungJTextField.setBackground(editColor); kmleistungJTextField.setForeground(textColor); kmleistungJTextField.setVisible(true); getContentPane().add(kmleistungJTextField); preisJLabel=new JLabel("Preis"); preisJLabel.setBounds(pl,po+=2*ph,pw,ph); preisJLabel.setFont(cFont); preisJLabel.setVisible(true); getContentPane().add(preisJLabel); preisJTextField=new JTextField(); preisJTextField.setBounds(pl+pw,po,pw,ph); preisJTextField.setFont(cFont); preisJTextField.setEditable(true); preisJTextField.setBackground(editColor); preisJTextField.setForeground(textColor); preisJTextField.setVisible(true); getContentPane().add(preisJTextField); okJButton= new JButton("OK"); okJButton.setBounds(plbutton=pl,po+=2*ph,pwbutton,ph); okJButton.setVisible(true); getContentPane().add(okJButton); okJButton.addActionListener(aInsertJDialogActionListener); clearJButton= new JButton("CLEAR"); clearJButton.setBounds(plbutton+=pdelta,po,pwbutton,ph); clearJButton.setVisible(true); getContentPane().add(clearJButton); clearJButton.addActionListener(aInsertJDialogActionListener); quitJButton= new JButton("QUIT"); quitJButton.setBounds(plbutton+=pdelta,po,pwbutton,ph); quitJButton.setVisible(true); getContentPane().add(quitJButton); quitJButton.addActionListener(aInsertJDialogActionListener); setVisible(false); } public Pkw getInsertPkw() { Pkw aPkw = insertPkw; insertPkw = null ; return aPkw; } /* Anzeige aller JTextField des eingefuegten Pkw */ private void displayJTextFields() { } /* Pruefung aller JTextFields der Eingabe vor Aufruf des Konstruktors */ private void checkEditableJTextFields() { errorcode = 0; typString = typJTextField.getText(); if( (0 == typString.length()) || (typString.length() > 20) ) { errorcode = 2; runMessageDialog(); return; } herstellerString = herstellerJTextField.getText(); if( (0 == herstellerString.length()) || (herstellerString.length() > 20) ) { errorcode = 3; runMessageDialog(); return; } farbeString = farbeJTextField.getText(); if( (0 == farbeString.length()) || (farbeString.length() > 20) ) { errorcode = 4; runMessageDialog(); return; } try { kmleistung = Integer.parseInt(kmleistungJTextField.getText()); } catch(NumberFormatException e) { errorcode = 6; } if( kmleistung > 999999 ) { errorcode = 5; runMessageDialog(); return; } try { preis = Integer.parseInt(preisJTextField.getText()); } catch(NumberFormatException e) { errorcode = 8; } if( preis > 999999 ) { errorcode = 7; runMessageDialog(); return; } } /* Ausgabe eines OptionPane Dialogs fuer errorcode = 0,1,2,...8 */ private void runMessageDialog() { String [] errorString = { "Der Pkw ist eingefuegt worden !\n" +"Weitere Eingaben sind erst nach\n" +"Anklicken von CLEAR moeglich !", "Neue Eingabe sind erst nach CLEAR moeglich !", "Typ hat 0 oder mehr als 20 Zeichen !", "Hersteller hat 0 oder mehr als 20 Zeichen !", "Farbe hat 0 oder mehr als 20 Zeichen !", "Kilometerleistung hat mehr als 6 Stellen !", "Kilometerleistumg enthaelt nichtnumerische Zeichen !", "Preis hat mehr als 6 Stellen !", "Preis enthaelt nichtnumerische Zeichen !" }; JOptionPane.showMessageDialog(this,errorString[errorcode]); } private void clearAllFields(){ typJTextField.setText(""); herstellerJTextField.setText(""); farbeJTextField.setText(""); kmleistungJTextField.setText(""); preisJTextField.setText(""); } /* CallBackMethodes *********************/ public void callBackOkJButton() { checkEditableJTextFields(); if(errorcode == 0){ insertPkw = new Pkw(typString.toUpperCase(), herstellerString.toUpperCase(), farbeString.toUpperCase(), kmleistung, preis); okJButton.setEnabled(false); } } public void callBackClearJButton() { clearAllFields(); okJButton.setEnabled(true); } public void callBackQuitJButton() { clearAllFields(); okJButton.setEnabled(true); setVisible(false); }}class InsertJDialogActionListener implements ActionListener{ InsertJDialog aJDialog; public InsertJDialogActionListener(InsertJDialog mJDialog) { aJDialog = mJDialog; } public void actionPerformed ( ActionEvent evt ) { String [] commandString = {"OK","CLEAR","QUIT"}; int i,nr=-1; for ( i=0, nr=-1 ; i < commandString.length ; i++ ) if ( commandString[i].equals(evt.getActionCommand())) { nr=i; break; } switch ( nr ) { case 0: aJDialog.callBackOkJButton(); break; case 1: aJDialog.callBackClearJButton(); break; case 2: aJDialog.callBackQuitJButton(); break; default: break; } }}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -