作为小白的我,今天学习了java中打开与关闭窗口的方法。
1.在java中创建一个窗口
import java.awt.*;
import java.awt.event.*;
public class LpqClient extends frame{
public void LaunchFrame(){
this.setLocation(300,400);
this.setSize(800,600);
this.setTittle("TANKWarlpq");
this.setVisible(true);
}
public static void main(String[]args){
LpqClient lc=new LpqClient();
lc.LaunchFrame();
}
}
2.在java中创建一个窗口并关掉保证窗口大小不可调节
import java.awt.*;
import java.awt.event.*;
public class LpqClient extends frame{
public void LaunchFrame(){
this.setLocation(300,400);
this.setSize(800,600);
this.setTittle("TANKWarlpq");//窗口标题
//关闭窗口
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);//退出
}
});
this.setResizable(false);//窗口大小不可变
setVisible(true);//显示窗口
}
public static void main(String[]args){
LpqClient lc=new LpqClient();
lc.LaunchFrame();
}
}