【发布时间】:2016-03-09 06:03:19
【问题描述】:
我是 java 的菜鸟,我在构建我的 gui 时遇到了障碍......我需要做的是运行我的 shippingApp 程序,该程序显示我的 EnterShipInfo 框架,该框架有几个文本字段用于输入数据和一个输入按钮,当clicked 将输入的数据传递给我的 ShipmentFrame。最初,当框架弹出时,应该有三个标签,其中只显示“标签”和一个显示按钮,然后当您单击显示按钮时,文本字段中的数据会在三个标签中弹出以及其他一些单词造句。
// ShipmentFrame 代码从这里开始
private static final long serialVersionUID = 1L;
private Label headerLbl = null;
private Button displayButton = null;
private Button Exit = null;
private Label shipLbl = null;
private Label empLbl = null;
private Label dateTimeLbl = null;
private Shipment s;
private Shipment sf;
public ShipmentFrame(Shipment ship){
super();
this.s = ship;
initialize();
s = ship;
}
public void actionPerformed(ActionEvent e) {
shipLbl.setText("Shipment number " + s.getShipmentNum() +
" was received from " + s.getSupplierName());
empLbl.setText("By employee number " + s.getEmployeeNum());
dateTimeLbl.setText("On " + s.getRevDate() + " at " + s.getRevTime());
}
// 这是我来自 EnterShipInfo 的代码
private static final long serialVersionUID = 1L;
private Label headerLbl = null;
private Button displayButton = null;
private Button Exit = null;
private Label dateLbl = null;
private Label timeLbl = null;
private Label suplLbl = null;
private Shipment s;
private Label shipNumLbl = null;
private Label empNumLbl = null;
private TextField empNumTF = null;
private TextField shipNumTF = null;
private TextField dateTF = null;
private TextField timeTF = null;
private TextField supplTF = null;
Shipment ship = new Shipment (" ", " ", " ", " ", " ");
// @jve:decl-index=0:
public EnterShipInfo(){
super();
// this.s = ship;
initialize();
}
//这是错误的部分
public void actionPerformed(ActionEvent e) {
String employeeNum = empNumTF.getText();
String shipmentNum = shipNumTF.getText();
String revDate = dateTF.getText();
String revTime = timeTF.getText();
String supplierName = supplTF.getText();
ShipmentFrame sf = new ShipmentFrame(null);
}
//下面是我一直在寻找的......也许有人知道更有效的方法来完成这个
public void actionPerformed(ActionEvent e) {
ship.setEmployeeNum(empNumTF.getText());
ship.setShipmentNum( shipNumTF.getText());
ship.setRevDate( dateTF.getText());
ship.setRevTime(timeTF.getText());
ship.setSupplierName( supplTF.getText());
ShipmentFrame sf = new ShipmentFrame(ship);
}
【问题讨论】:
-
您是否有特定的问题或遇到的特定问题?
-
事实上有一个特定的问题,直到点击第二帧(shipmentFrame)上的显示按钮......当我点击显示按钮时,我当然得到错误,所以我的想法是我犯了两个可能的错误之一,要么我没有将文本字段中的信息传递给对象,要么我在单击显示按钮时未能调用它们
-
将错误复制并粘贴到您问题中的另一个代码块中,以便我们查看到底发生了什么。