急求这个JAVA程序的编写代码。。。
编写一个Application,创建并显示一个200*100的Frame,该Frame的标题为:”Hello”。向Frame容器中添加一个标签为”PressMe”的按钮。...
编写一个Application,创建并显示一个200*100的Frame,该Frame的标题为:”Hello”。向Frame容器中添加一个标签为”Press Me”的按钮。编写代码,使得按钮被点击后,系统输出”您好! 欢迎进入Java世界!”字符串。要求程序能够处理窗口的关闭,正常退出。
附:可能用到的工具:
WindowListener接口中包括的方法定义:
public void windowClosing(WindowEvent e);
public void windowOpened(WindowEvent e);
public void windowIconified(WindowEvent e);
public void windowDeiconified(WindowEvent e);
public void windowClosed(WindowEvent e);
public void windowActivated(WindowEvent e);
public void windowDeactivated(WindowEvent e);
ActionListener接口中包括的方法定义:
public void actionPerformed(ActionEvent e); 展开
附:可能用到的工具:
WindowListener接口中包括的方法定义:
public void windowClosing(WindowEvent e);
public void windowOpened(WindowEvent e);
public void windowIconified(WindowEvent e);
public void windowDeiconified(WindowEvent e);
public void windowClosed(WindowEvent e);
public void windowActivated(WindowEvent e);
public void windowDeactivated(WindowEvent e);
ActionListener接口中包括的方法定义:
public void actionPerformed(ActionEvent e); 展开
6个回答
展开全部
第一次写application。写的不好,请见谅!!!
import javax.swing.*;
import java.awt.event.*;
import java.awt.BorderLayout;
public class GUIApplet extends JApplet
{
private JButton btn;
private JLabel lbl;
private JPanel p;
public void init()
{
System.out.println("Init Applet");
}
public void start()
{
System.out.println("Start Applet");
p = new JPanel();
btn = new JButton("Press Me");
lbl = new JLabel("djfjdl");
setLayout(new BorderLayout());
add(btn,BorderLayout.CENTER);
add(lbl,BorderLayout.NORTH);
btn.addActionListener(new MyListener());
this.setSize(200, 100);
}
class MyListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == btn)
{
lbl.setText("欢迎来到java世界");
}
}
}
//at.setSize(200, 100);
//at.setVisible(true);
//at.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
public void stop()
{
System.out.println("Stop Applet");
}
public void destroy()
{
System.out.println("Destory Applet");
}
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<TITLE>
<TITLE> Application </TITLE>
</TITLE>
<BODY>
This is a simple applet.<p>
<applet code = "GUIApplet.class" width = "1028" height = "800">
</applet>
</BODY>
</HTML>
import javax.swing.*;
import java.awt.event.*;
import java.awt.BorderLayout;
public class GUIApplet extends JApplet
{
private JButton btn;
private JLabel lbl;
private JPanel p;
public void init()
{
System.out.println("Init Applet");
}
public void start()
{
System.out.println("Start Applet");
p = new JPanel();
btn = new JButton("Press Me");
lbl = new JLabel("djfjdl");
setLayout(new BorderLayout());
add(btn,BorderLayout.CENTER);
add(lbl,BorderLayout.NORTH);
btn.addActionListener(new MyListener());
this.setSize(200, 100);
}
class MyListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == btn)
{
lbl.setText("欢迎来到java世界");
}
}
}
//at.setSize(200, 100);
//at.setVisible(true);
//at.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
public void stop()
{
System.out.println("Stop Applet");
}
public void destroy()
{
System.out.println("Destory Applet");
}
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<TITLE>
<TITLE> Application </TITLE>
</TITLE>
<BODY>
This is a simple applet.<p>
<applet code = "GUIApplet.class" width = "1028" height = "800">
</applet>
</BODY>
</HTML>
展开全部
大哥啊,这个还要问别人啊!!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
有意思
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
刚学JBuilder时候 不就干这活吗?
同学要好好学啊~
同学要好好学啊~
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
import java.awt.*;
import java.awt.event.*;//此包必须引入
public class MyFrame extends WindowAdapter implements ActionListener{
Button l;
Frame fr;
public static void main(String args[]){
MyFrame m=new MyFrame();
m.init();}
public void init(){
fr=new Frame("Hello");
l=new Button("Press Me");
fr.add(l,"Center");
fr.addWindowListener(this);
l.addActionListener(this);
fr.setSize(200,100); //窗口大小为200*100
fr.setVisible(true); //设置窗口可见
}
public void actionPerformed(ActionEvent e){
System.out.println("您好,欢迎进入JAVA世界!");
}
public void windowClosing(WindowEvent e){System.exit(0);}
}
import java.awt.event.*;//此包必须引入
public class MyFrame extends WindowAdapter implements ActionListener{
Button l;
Frame fr;
public static void main(String args[]){
MyFrame m=new MyFrame();
m.init();}
public void init(){
fr=new Frame("Hello");
l=new Button("Press Me");
fr.add(l,"Center");
fr.addWindowListener(this);
l.addActionListener(this);
fr.setSize(200,100); //窗口大小为200*100
fr.setVisible(true); //设置窗口可见
}
public void actionPerformed(ActionEvent e){
System.out.println("您好,欢迎进入JAVA世界!");
}
public void windowClosing(WindowEvent e){System.exit(0);}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询