当我按下按钮时,我想要一个弹出窗口。可以用正确的代码告诉我。这是我的代码。我是java swings的新手。请提前感谢。我的代码是。
JButton testButton=new JButton("test");
toolBar.addComponentRight(testButton);
testButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
here I want to replace code--------
JOptionPane.showMessageDialog(null,"you clicked me");
}
});
Here in output pop up window I am getting only OK button.I need CANCEL button also along with OK button.Can anyone suggest me with the right code.Thank you in advance.
答案 0 :(得分:2)
你可以做同样的事情,
JOptionPane.showConfirmDialog((Component) null, "Do you want to close ?", "Window Title", JOptionPane.OK_CANCEL_OPTION);
它同样会显示,
答案 1 :(得分:0)
I got the code.I hope it would be useful.here is my modified code.Thank you vishal.
JButton testButton=new JButton("test");
toolBar.addComponentRight(testButton);
testButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
JOptionPane.showConfirmDialog((Component) null, "Do you want to close ?", "Window Title", JOptionPane.OK_CANCEL_OPTION);
}
});