java编程窗体上有黑色和白色两个按钮一个标签单击黑色按钮窗体颜色变成黑色单
1个回答
展开全部
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;import javax.swing.JFrame;
import javax.swing.JOptionPane;public class SimpleFrame {public static void main(String[] args) {
MyFrame frame = new MyFrame();
frame.setDefaultCloseOperation( JFrame.DO_NOTHING_ON_CLOSE);
frame.setVisible(true);
}
}
class MyFrame extends JFrame
{
public MyFrame()
{
this.setSize( 300, 200);
this.setResizable( false);
this.addWindowListener(new MyListener(this));
}
private class MyListener extends WindowAdapter
{
JFrame myFrame;
public MyListener( JFrame f)
{
myFrame = f;
}
@Override
public void windowClosing(WindowEvent arg0) {
int test = JOptionPane.showConfirmDialog( myFrame, "确定要退出吗?","退出确认",
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if( test == JOptionPane.YES_OPTION)
System.exit(0);
else
return;
}
}
}
import java.awt.event.WindowEvent;import javax.swing.JFrame;
import javax.swing.JOptionPane;public class SimpleFrame {public static void main(String[] args) {
MyFrame frame = new MyFrame();
frame.setDefaultCloseOperation( JFrame.DO_NOTHING_ON_CLOSE);
frame.setVisible(true);
}
}
class MyFrame extends JFrame
{
public MyFrame()
{
this.setSize( 300, 200);
this.setResizable( false);
this.addWindowListener(new MyListener(this));
}
private class MyListener extends WindowAdapter
{
JFrame myFrame;
public MyListener( JFrame f)
{
myFrame = f;
}
@Override
public void windowClosing(WindowEvent arg0) {
int test = JOptionPane.showConfirmDialog( myFrame, "确定要退出吗?","退出确认",
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if( test == JOptionPane.YES_OPTION)
System.exit(0);
else
return;
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |