新人求教java窗体,有些问题不是很懂~! javawindows 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import java.awt.event.*;import java.awt.*; 还有你这个方法this.addWindowListener也有问题吧; import java.awt.*;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;public class Day1015_Frame extends Frame{ public static void main(String[] args) { Frame frame =new Frame("My first windows"); frame.setLayout(new GridLayout(7,1)); //lable组件 frame.add(new Label("喜好选择(可复选):")); //checkbox组件 frame.add(new Checkbox("音乐")); frame.add(new Checkbox("体育")); frame.add(new Checkbox("美术")); //Choice 组件 Choice c=new Choice(); c.add("Red"); c.add("Green"); c.add("Blue"); frame.add(c); //List组件 List l=new List(3,false); l.add("一年级"); l.add("二年级"); l.add("三年级"); frame.add(l); //Button组件 frame.add(new Button("测试按钮")); frame.pack();//调整窗口以容纳所有的组件 frame.setVisible(true);//显示窗口 new Day1015_Frame().launch(); } public void launch() { this.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { System.exit(0); } }); } } java.awt.* 不是把WindowAdapter 这些包括在里面了吗 import java.awt.Button;import java.awt.Checkbox;import java.awt.Choice;import java.awt.Frame;import java.awt.GridLayout;import java.awt.Label;import java.awt.List;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;public class Day1015_Frame extends Frame{ public static void main(String[] args){ new Day1015_Frame().launch(); } public void launch() { this.setLayout(new GridLayout(7,1)); //lable组件 this.add(new Label("喜好选择(可复选):")); //checkbox组件 this.add(new Checkbox("音乐")); this.add(new Checkbox("体育")); this.add(new Checkbox("美术")); //Choice 组件 Choice c=new Choice(); c.add("Red"); c.add("Green"); c.add("Blue"); this.add(c); //List组件 List l=new List(3,false); l.add("一年级"); l.add("二年级"); l.add("三年级"); this.add(l); //Button组件 this.add(new Button("测试按钮")); this.pack();//调整窗口以容纳所有的组件 this.setVisible(true);//显示窗口 this.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { System.exit(0); } }); } }可以关了,直接继承自Frame就行。 不对啊 ..点击关闭窗口 还是没反应啊.窗口不会关闭import java.awt.*;import java.awt.event.*;public class test{ public static void main(String[] args) { Frame frame =new Frame("My first windows"); frame.setLayout(new GridLayout(7,1)); //lable组件 frame.add(new Label("喜好选择(可复选):")); //checkbox组件 frame.add(new Checkbox("音乐")); frame.add(new Checkbox("体育")); frame.add(new Checkbox("美术")); //Choice 组件 Choice c=new Choice(); c.add("Red"); c.add("Green"); c.add("Blue"); frame.add(c); //List组件 List l=new List(3,false); l.add("一年级"); l.add("二年级"); l.add("三年级"); frame.add(l); //Button组件 frame.add(new Button("测试按钮")); frame.pack();//调整窗口以容纳所有的组件 frame.setVisible(true);//显示窗口// new test().launch(); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { System.exit(0); } }); }// public void launch() {// // }// } 不对啊 ..点击关闭窗口 还是没反应啊.窗口不会关闭把Frame改为JFrame就行了import java.awt.*;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import javax.swing.JFrame;public class Day1015_Frame extends JFrame{ public static void main(String[] args) { JFrame frame =new JFrame("My first windows"); frame.setLayout(new GridLayout(7,1)); //lable组件 frame.add(new Label("喜好选择(可复选):")); //checkbox组件 frame.add(new Checkbox("音乐")); frame.add(new Checkbox("体育")); frame.add(new Checkbox("美术")); //Choice 组件 Choice c=new Choice(); c.add("Red"); c.add("Green"); c.add("Blue"); frame.add(c); //List组件 List l=new List(3,false); l.add("一年级"); l.add("二年级"); l.add("三年级"); frame.add(l); //Button组件 frame.add(new Button("测试按钮")); frame.pack();//调整窗口以容纳所有的组件 frame.setVisible(true);//显示窗口 new Day1015_Frame().launch(); } public void launch() { this.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { System.exit(0); } }); } } 也可以写成这样frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); swing中在JTextArea控件中输入半行文字,然后回车,为什么不换行呢?? 关于JAVA打包和扩大JVM内存的纠结问题 如何控制SWT Text 的输入格式 一个生产者消费者线程关闭的问题 JAVA访问pcom 这里的this分别可以用什么代替 有没有好的方案可以实现java界面的快速生成和重用? 关于异常的小问题,请大虾们解释一下!!!! 关于tomcat下的jsp问题 关于JTabeedPane中多个JPane的显示问题 JAVA一个例子没看懂 求大神给我看一下ios推送的问题
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;public class Day1015_Frame extends Frame
{
public static void main(String[] args)
{ Frame frame =new Frame("My first windows");
frame.setLayout(new GridLayout(7,1));
//lable组件
frame.add(new Label("喜好选择(可复选):"));
//checkbox组件
frame.add(new Checkbox("音乐"));
frame.add(new Checkbox("体育"));
frame.add(new Checkbox("美术"));
//Choice 组件
Choice c=new Choice();
c.add("Red");
c.add("Green");
c.add("Blue");
frame.add(c);
//List组件
List l=new List(3,false);
l.add("一年级");
l.add("二年级");
l.add("三年级");
frame.add(l);
//Button组件
frame.add(new Button("测试按钮"));
frame.pack();//调整窗口以容纳所有的组件
frame.setVisible(true);//显示窗口
new Day1015_Frame().launch(); } public void launch() {
this.addWindowListener(new WindowAdapter() { @Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
}
import java.awt.Checkbox;
import java.awt.Choice;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.List;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;public class Day1015_Frame extends Frame{
public static void main(String[] args){
new Day1015_Frame().launch();
} public void launch() {
this.setLayout(new GridLayout(7,1));
//lable组件
this.add(new Label("喜好选择(可复选):"));
//checkbox组件
this.add(new Checkbox("音乐"));
this.add(new Checkbox("体育"));
this.add(new Checkbox("美术"));
//Choice 组件
Choice c=new Choice();
c.add("Red");
c.add("Green");
c.add("Blue");
this.add(c);
//List组件
List l=new List(3,false);
l.add("一年级");
l.add("二年级");
l.add("三年级");
this.add(l);
//Button组件
this.add(new Button("测试按钮"));
this.pack();//调整窗口以容纳所有的组件
this.setVisible(true);//显示窗口
this.addWindowListener(new WindowAdapter() { @Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
}
可以关了,直接继承自Frame就行。
import java.awt.*;
import java.awt.event.*;public class test
{
public static void main(String[] args)
{ Frame frame =new Frame("My first windows");
frame.setLayout(new GridLayout(7,1));
//lable组件
frame.add(new Label("喜好选择(可复选):"));
//checkbox组件
frame.add(new Checkbox("音乐"));
frame.add(new Checkbox("体育"));
frame.add(new Checkbox("美术"));
//Choice 组件
Choice c=new Choice();
c.add("Red");
c.add("Green");
c.add("Blue");
frame.add(c);
//List组件
List l=new List(3,false);
l.add("一年级");
l.add("二年级");
l.add("三年级");
frame.add(l);
//Button组件
frame.add(new Button("测试按钮"));
frame.pack();//调整窗口以容纳所有的组件
frame.setVisible(true);//显示窗口// new test().launch();
frame.addWindowListener(new WindowAdapter() { @Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}// public void launch() {
//
// }
//
}
把Frame改为JFrame就行了
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;import javax.swing.JFrame;public class Day1015_Frame extends JFrame
{
public static void main(String[] args)
{ JFrame frame =new JFrame("My first windows");
frame.setLayout(new GridLayout(7,1));
//lable组件
frame.add(new Label("喜好选择(可复选):"));
//checkbox组件
frame.add(new Checkbox("音乐"));
frame.add(new Checkbox("体育"));
frame.add(new Checkbox("美术"));
//Choice 组件
Choice c=new Choice();
c.add("Red");
c.add("Green");
c.add("Blue");
frame.add(c);
//List组件
List l=new List(3,false);
l.add("一年级");
l.add("二年级");
l.add("三年级");
frame.add(l);
//Button组件
frame.add(new Button("测试按钮"));
frame.pack();//调整窗口以容纳所有的组件
frame.setVisible(true);//显示窗口
new Day1015_Frame().launch(); } public void launch() {
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
}
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);