如何点了jbutton退出按钮就退出java程序
packagemypack;importjava.awt.Color;importjava.awt.Font;importjavax.swing.JButton;impo...
package mypack;
import java.awt.Color;
import java.awt.Font;
import javax.swing.JButton;
import javax.swing.JDialog;
import org.dyno.visual.swing.layouts.Constraints;
import org.dyno.visual.swing.layouts.GroupLayout;
import org.dyno.visual.swing.layouts.Leading;
//VS4E -- DO NOT REMOVE THIS LINE!
public class DDDDDDD extends JDialog {
private static final long serialVersionUID = 1L;
private JButton jButton0;
private static final String PREFERRED_LOOK_AND_FEEL = "javax.swing.plaf.metal.MetalLookAndFeel";
public DDDDDDD() {
initComponents();
}
private void initComponents() {
setFont(new Font("Dialog", Font.PLAIN, 12));
setBackground(Color.white);
setForeground(Color.black);
setLayout(new GroupLayout());
add(getJButton0(), new Constraints(new Leading(103, 115, 10, 10), new Leading(63, 75, 10, 10)));
setSize(320, 240);
}
private JButton getJButton0() {
if (jButton0 == null) {
jButton0 = new JButton();
jButton0.setFont(new Font("Dialog", Font.BOLD, 26));
jButton0.setText("退出");
}
return jButton0;
}
}
如何点击了退出过后就关闭程序??
添加了
jButton0.addActionListener(
new ActionListener(){
public void performed(ActionEvent event) {
System.exit(0);
}
}
);
但是这里 new ActionListener 报错 展开
import java.awt.Color;
import java.awt.Font;
import javax.swing.JButton;
import javax.swing.JDialog;
import org.dyno.visual.swing.layouts.Constraints;
import org.dyno.visual.swing.layouts.GroupLayout;
import org.dyno.visual.swing.layouts.Leading;
//VS4E -- DO NOT REMOVE THIS LINE!
public class DDDDDDD extends JDialog {
private static final long serialVersionUID = 1L;
private JButton jButton0;
private static final String PREFERRED_LOOK_AND_FEEL = "javax.swing.plaf.metal.MetalLookAndFeel";
public DDDDDDD() {
initComponents();
}
private void initComponents() {
setFont(new Font("Dialog", Font.PLAIN, 12));
setBackground(Color.white);
setForeground(Color.black);
setLayout(new GroupLayout());
add(getJButton0(), new Constraints(new Leading(103, 115, 10, 10), new Leading(63, 75, 10, 10)));
setSize(320, 240);
}
private JButton getJButton0() {
if (jButton0 == null) {
jButton0 = new JButton();
jButton0.setFont(new Font("Dialog", Font.BOLD, 26));
jButton0.setText("退出");
}
return jButton0;
}
}
如何点击了退出过后就关闭程序??
添加了
jButton0.addActionListener(
new ActionListener(){
public void performed(ActionEvent event) {
System.exit(0);
}
}
);
但是这里 new ActionListener 报错 展开
3个回答
展开全部
jButton0.addActionListener(
new ActionListener(){
public void performed(ActionEvent event) {
System.exit(0);
}
}
);
在getJButton0的最后添加上面的代码
new ActionListener(){
public void performed(ActionEvent event) {
System.exit(0);
}
}
);
在getJButton0的最后添加上面的代码
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
});
performed方法名字写错了!~
public void actionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
});
performed方法名字写错了!~
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
加一句System.exit(0)就行。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询