刚学到awt工具集,有个例子执行后却没有半点反应,是不是少了什么?

LAKERS_KOBE24 2009-11-14 10:32:30
刚学到awt工具集,有个例子执行后却没有半点反应,是不是少了什么?附例如下:
import java.awt.*;
public class Demo{
public static void main(String[] args){
Frame fr=new Frame("媒体新闻");
fr.setLayout(new FlowLayout());
Button button1=new Button("确定");
Button button2=new Button("取消");
fr.add(button1);
fr.add(button2);
fr.setSize(200,300);
fr.setBackground(Color.cyan);
fr.validate();
}
}
...全文
67 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
liuyake250 2009-11-14
  • 打赏
  • 举报
回复
你都没设置窗口显示啊老大
加上这个试试fr.setVisible(true);
爱摸鱼de老邪 2009-11-14
  • 打赏
  • 举报
回复

import java.awt.*;
public class Demo{
public static void main(String[] args){
Frame fr=new Frame("媒体新闻");
fr.setLayout(new FlowLayout());
Button button1=new Button("确定");
Button button2=new Button("取消");
fr.add(button1);
fr.add(button2);
fr.setSize(200,300);
fr.setBackground(Color.cyan);
fr.setVisible(true);
}
}

用错一个方法而已,没楼上描述的那么复杂。
JavaAlpha 2009-11-14
  • 打赏
  • 举报
回复
可以参考一下 我给的一个小例子。这个也是一个csdn的朋友写的。
JavaAlpha 2009-11-14
  • 打赏
  • 举报
回复
package com.alpha.test;

/*
* QQ 登录界面
* date:2009-10-21 19:52:36
* author:JavaAlpha
*/

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

public class Main1 extends JFrame implements ActionListener
{
private static final long serialVersionUID = 1L;
JLabel jlb1, jlb2;
JButton jb1, jb2;
JTextField jtf;
JPasswordField jpf;

public Main1()
{
// 创建组件
jlb1 = new JLabel("Q号");
jlb2 = new JLabel("密码");
jb1 = new JButton();
jb2 = new JButton();
jtf = new JTextField();
jpf = new JPasswordField();
// 设置布局
this.setLayout(new GridLayout(3, 2));
// 添加组件
this.add(jlb1);
this.add(jtf);
this.add(jlb2);
this.add(jpf);
this.add(jb1);
this.add(jb2);
// 添加监听
// 展现窗体
this.setSize(330, 200);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}

public static void main(String[] args)
{
new Main1();
}

public void actionPerformed(ActionEvent arg0)
{
}

}
JavaAlpha 2009-11-14
  • 打赏
  • 举报
回复
import java.awt.*;
public class Demo extends JFrame{ //要继承JFrame
public static void main(String[] args){
Frame fr=new Frame("媒体新闻");
fr.setLayout(new FlowLayout());
Button button1=new Button("确定");
Button button2=new Button("取消");
fr.add(button1);
fr.add(button2);
fr.setSize(200,300);
fr.setBackground(Color.cyan);
fr.validate();
this.setVisible(true);//这句是现实frame的
}
}
LAKERS_KOBE24 2009-11-14
  • 打赏
  • 举报
回复
晕,谢谢鸟!

62,621

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧