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

📄 editjdialog.java

📁 二手车管理软件
💻 JAVA
字号:
/** Programmname : EditJDialog <br>Klasse : <b> EditJDialog </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 EditJDialog extends PkwGUI {	private PkwArray aPkwArray;	private int posPkwArr;	private Pkw editPkw;	private Pkw deletePkw;	private Pkw updatePkw;	private JButton updateJButton, resetJButton, quitJButton, deleteJButton,			prevJButton, nextJButton;	private EditJDialogActionListener aEditJDialogActionListener;	private int plbutton, pwbutton = 100, pdelta = 120;		/** Konstuktor EditJDialog */	public EditJDialog(MainGUI aGUI, boolean mode) {		super(aGUI, mode);		setSize(400, 580);		setLocation(500, 10);		actionJLabel.setText("EDIT Pkw");		typJTextField.setEditable(false);		typJTextField.setBackground(noeditColor);		herstellerJTextField.setEditable(false);		herstellerJTextField.setBackground(noeditColor);		aEditJDialogActionListener = new EditJDialogActionListener(this);		updateJButton = new JButton("UPDATE");		updateJButton.setBounds(plbutton = pl, po += 2 * ph, pwbutton, ph);		updateJButton.setVisible(true);		getContentPane().add(updateJButton);		updateJButton.addActionListener(aEditJDialogActionListener);		resetJButton = new JButton("RESET");		resetJButton.setBounds(plbutton += pdelta, po, pwbutton, ph);		resetJButton.setVisible(true);		getContentPane().add(resetJButton);		resetJButton.addActionListener(aEditJDialogActionListener);		quitJButton = new JButton("QUIT");		quitJButton.setBounds(plbutton += pdelta, po, pwbutton, ph);		quitJButton.setVisible(true);		getContentPane().add(quitJButton);		quitJButton.addActionListener(aEditJDialogActionListener);		deleteJButton = new JButton("DELETE");		deleteJButton.setBounds(plbutton = pl, po += 2 * ph, pwbutton, ph);		deleteJButton.setVisible(true);		getContentPane().add(deleteJButton);		deleteJButton.addActionListener(aEditJDialogActionListener);		prevJButton = new JButton("PREV");		prevJButton.setBounds(plbutton += pdelta, po, pwbutton, ph);		prevJButton.setVisible(true);		getContentPane().add(prevJButton);		prevJButton.addActionListener(aEditJDialogActionListener);		nextJButton = new JButton("NEXT");		nextJButton.setBounds(plbutton += pdelta, po, pwbutton, ph);		nextJButton.setVisible(true);		getContentPane().add(nextJButton);		nextJButton.addActionListener(aEditJDialogActionListener);	}		/** liefert den gel鰏chten Pkw zur點k */	public Pkw getDeletePkw()	{		Pkw aPkw = deletePkw;		deletePkw = null;		return aPkw;	}	/** liefert ge鋘derten Pkw zur點k */	public Pkw getUpdatePkw()	{		Pkw  aPkw = updatePkw;		updatePkw = null ;		return aPkw;	}	/**  */	public void setLinkPkwArray(PkwArray p) {		if (p != null) {			aPkwArray = p;		}	}	public void setPosition(int j) {		posPkwArr = j;		editPkw = aPkwArray.getPkw(posPkwArr);		displayJTextFields(editPkw);	}	private void displayJTextFields(Pkw aPkw) {		if (editPkw != null) {			identnummerJTextField.setText(Integer.toString(aPkw.getIdentnummer()));			typJTextField.setText(aPkw.getTyp());			herstellerJTextField.setText(aPkw.getHersteller());			farbeJTextField.setText(aPkw.getFarbe());			kmleistungJTextField.setText(Integer.toString(editPkw.getKmleistung()));			preisJTextField.setText(Integer.toString(aPkw.getPreis()));		}	}	private void checkEditableJTextFields() {		errorcode = 0;		farbeString = farbeJTextField.getText().toUpperCase();		if (farbeString.length() == 0 || farbeString.length() > 20) {			errorcode = 4;			return;		}		kmleistungString = kmleistungJTextField.getText();		if (kmleistungString.length() == 0) kmleistungString = "0";		try {			kmleistung = Integer.parseInt(kmleistungString);		} catch (NumberFormatException nex) {			errorcode = 6;			return;		}		if (kmleistung < 0 || kmleistung >= 1000000) {			errorcode = 5;			return;		}		preisString = preisJTextField.getText();		if (preisString.length() == 0)			preisString = "0";		try {			preis = Integer.parseInt(preisString);		} catch (NumberFormatException nex) {			errorcode = 8;			return;		}		if (preis < 0 || preis >= 1000000) {			errorcode = 7;			return;		}		return;	}	public void callBackUpdateJButton() {		checkEditableJTextFields();		if (errorcode == 0) {			editPkw.setFarbe(farbeString);			editPkw.setKmleistung(kmleistung);			editPkw.setPreis(preis);			updatePkw = editPkw;			displayJTextFields(editPkw);			aPkwArray.changes();			JOptionPane.showMessageDialog(this, "Update ist erfolgt !");		} else			runMessageDialog();	}	public void callBackResetJButton() {		farbeJTextField.setText(editPkw.getFarbe());		kmleistungJTextField.setText(Integer.toString(editPkw.getKmleistung()));		preisJTextField.setText(Integer.toString(editPkw.getPreis()));	}	public void callBackQuitJButton() {		setVisible(false);	}	public void callBackDeleteJButton() {		int n = JOptionPane.showConfirmDialog(this,				"Wollen Sie wiklich loeschen?", "Confirm Dialog",				JOptionPane.YES_NO_OPTION);		if (n == 0) {			deletePkw = editPkw;			Pkw.delete(editPkw);			if (0 == aPkwArray.getCount()){				editPkw = null;				updatePkw = null;				deletePkw = null;				JOptionPane.showMessageDialog(this, "Delete ist erfolgt !");				JOptionPane.showMessageDialog(this, "Anzahl Pkws ist 0 !");				setVisible(false);			}			else{				if (aPkwArray.getCount() > (posPkwArr)) editPkw=aPkwArray.getPkw(posPkwArr);				else if (posPkwArr > 0)  editPkw=aPkwArray.getPkw(--posPkwArr);				displayJTextFields(editPkw);				JOptionPane.showMessageDialog(this, "Delete ist erfolgt !");			}					}	}	public void callBackPrevJButton() {		if (posPkwArr > 0) {			editPkw = (Pkw) aPkwArray.getPkw(--posPkwArr);			displayJTextFields(editPkw);		} else			JOptionPane					.showMessageDialog(this, "Kein weiterer Pkw vorhanden !");	}	public void callBackNextJButton() {		if (aPkwArray.getCount() > (posPkwArr + 1)) {			editPkw = (Pkw) aPkwArray.getPkw(++posPkwArr);			displayJTextFields(editPkw);		} else			JOptionPane					.showMessageDialog(this, "Kein weiterer Pkw vorhanden !");	}}class EditJDialogActionListener implements ActionListener{  EditJDialog   aJDialog;  public EditJDialogActionListener(EditJDialog mJDialog)  { aJDialog = mJDialog; }  public void actionPerformed ( ActionEvent evt )  {    String [] commandString ={"UPDATE","RESET","QUIT","DELETE","PREV","NEXT"};    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.callBackUpdateJButton();                break;      case 1 :  aJDialog.callBackResetJButton();                break;      case 2 :  aJDialog.callBackQuitJButton();                break;      case 3 :  aJDialog.callBackDeleteJButton();                break;      case 4 :  aJDialog.callBackPrevJButton();                break;      case 5 :  aJDialog.callBackNextJButton();                break;      default : break;    }  }}

⌨️ 快捷键说明

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