これは私のコードですどのようにアクションリスナーを追加できますか?私は既に知られているメソッドを試しましたが、静的メソッドのために追加できません.Netbeans IDEはプログラムのアクションリスナーを提案しましたそれを使用することができない人は、アクションリスナーを宣言するより簡単な方法を提案することができます。gridbaglayoutにアクションリスナーを追加できません
パブリッククラスのCalc {
public static void addComponentsToPane(Container pane) {
pane.setLayout(new GridBagLayout());
GridBagConstraints gBC = new GridBagConstraints();
gBC.ipady = 40;
gBC.ipadx = 40;
JTextField JTextField = new JTextField("Hello");
gBC.fill = GridBagConstraints.HORIZONTAL;
gBC.gridx = 0;
gBC.gridy = 0;
gBC.gridwidth = 4;
JTextField.setEditable(false);
pane.add(JTextField, gBC);
//JButton jbnButton;
gBC.gridwidth = 1;
JButton b7 = new JButton("7");
gBC.gridx = 0;
gBC.gridy = 1;
pane.add(b7, gBC);
// more calculator buttons declared here
//ここではactionlistner
b0.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
b0ActionPerformed(evt);
}
private void b0ActionPerformed(ActionEvent evt) }
`
});
b0.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
b0ActionPerformed(evt);
}
private void b0ActionPerformed(Actionenter Event evt) {}
});}
private static void createAndShowGUI() {}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
示唆どのように}私はあなたのためにこれを試してみてください
SOにようこそ。 https://stackoverflow.com/help/how-to-askを読むことを検討してください。どのコンポーネントにactionListenerを追加したいのですか?これまでに何を試みましたか? –
私の電卓ボタンが目的の操作を実行するコードのどこにでもリスナーを追加したい。クリックすると – Prapti