我需要查看您的课程以更好地了解您要做什么。这是一个 Web 应用程序、一个客户端应用程序还是一个简单的单用户 GUI?
我想您不需要将其设为静态,只需作为实例成员并进行适当设置即可。
举个例子:
class UI {
// GUI members:
private JButton txMaxUserQueryButton;
/* Omitted GUI instance vars */
// User input members:
private double txMax;
/* Omitted user input vars */
// Constructor:
public UI() {
/* Omitted code, construct GUI members */
this.txMaxUserQueryButton = new JButton("Enter txMax val!");
/* More omitted code, construct GUI members */
this.addEventHandlers();
this.renderLayout();
}
private void addEventHandlers() {
/* Omitted code, add event handlers */
this.txMaxUserQueryButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String txMaxStrVal = String.valueOf(JOptionPane.showInputDialog("Entrer le seuil MAXIMAL de TxPower a dessus de lequel \n on recommande une intervention immédiate "));
JOptionPane.showMessageDialog(null,"la nouvelle TxPower est : "+"-"+txMaxStrVal+"dBm");
double txmax_reel = Double.parseDouble(txMaxStrVal);
setTxMax(txmax_reel);
}
});
/* More omitted code, add event handlers */
}
public void renderLayout() {
/* Omitted code, renders layout */
}
// Getters:
public double getTxMax() {
return this.txMax;
}
/* Omitted Getters for other vars */
// Setters:
public void setTxMax(double txMax) {
this.txMax = txMax;
}
/* Omitted Setters for other vars */
}
希望这可以帮助你...