创建一个简单的java 应用程序界面,实现一个关闭按钮
1.界面上自己实现一个“关闭按钮”窗口的功能。2.普通的记事本写的程序。不要引用eclipse的swt包等内容。(这点非常重要)...
1.界面上自己实现一个“关闭按钮”窗口的功能。
2.普通的记事本写的程序。不要引用eclipse的swt包等内容。(这点非常重要) 展开
2.普通的记事本写的程序。不要引用eclipse的swt包等内容。(这点非常重要) 展开
3个回答
展开全部
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class MyFrame extends JFrame {
private MyFrame instance = this;
/**
* @param args
*/
public static void main(String[] args) {
new MyFrame();
}
public MyFrame() {
this.setLayout(new FlowLayout());
JButton b = new JButton("close");
this.setSize(200,200);
this.add(b);
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
instance.dispose();
}
});
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
this.setVisible(true);
}
}
100分呀。用JDK的SWING写的,绝对不带SWT。分呀分呀。
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class MyFrame extends JFrame {
private MyFrame instance = this;
/**
* @param args
*/
public static void main(String[] args) {
new MyFrame();
}
public MyFrame() {
this.setLayout(new FlowLayout());
JButton b = new JButton("close");
this.setSize(200,200);
this.add(b);
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
instance.dispose();
}
});
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
this.setVisible(true);
}
}
100分呀。用JDK的SWING写的,绝对不带SWT。分呀分呀。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
import java.awt.*;
import java.awt.event.*;
public class TestWindowEvent {
public static void main (String[] args) {
new Frame88 ("WindowAdapter");
}
}
class Frame88 extends Frame {
Frame88 (String s) {
super(s);
setBounds (300,300,200,70);
setLayout (null);
setVisible (true);
addWindowListener (new WindowAdapter() {
public void windowClosing(WindowEvent e) {
setVisible (false);
System.exit(0);
}
} );
}
}
import java.awt.event.*;
public class TestWindowEvent {
public static void main (String[] args) {
new Frame88 ("WindowAdapter");
}
}
class Frame88 extends Frame {
Frame88 (String s) {
super(s);
setBounds (300,300,200,70);
setLayout (null);
setVisible (true);
addWindowListener (new WindowAdapter() {
public void windowClosing(WindowEvent e) {
setVisible (false);
System.exit(0);
}
} );
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
import java.awt.*;
import java.awt.event.*;
public class TestWindowEvent {
JButton jb;
public static void main (String[] args) { //主函数
new F ("WindowAdapter"); //调用
}
public void F () {
jb=new JButton("关闭");
this.add(jb);
setBounds (300,300,200,70);
setLayout (null);
setVisible (true);
jb.addMouseListener (new MouseAdapter() {
public void MouseClosing(MouseEvent e) {
setVisible (true);
System.exit(0);
}
} );
}
}
import java.awt.event.*;
public class TestWindowEvent {
JButton jb;
public static void main (String[] args) { //主函数
new F ("WindowAdapter"); //调用
}
public void F () {
jb=new JButton("关闭");
this.add(jb);
setBounds (300,300,200,70);
setLayout (null);
setVisible (true);
jb.addMouseListener (new MouseAdapter() {
public void MouseClosing(MouseEvent e) {
setVisible (true);
System.exit(0);
}
} );
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询