java界面编辑

import java.awt.*;
public class TestFrame extends java.applet.Applet{
	public static void main(String arg[]){
		Frame f = new Frame("A Test Window");//窗口标题
		f.setSize(250,150);//调整窗口大小
		f.setVisible(true);
		
	}
public void paint(Graphics g){
		
	}
}
//一个最简单的窗口函数


import java.awt.*;
public class Login {
	public static void main(String arg[]){
		Frame f = new Frame("User Login");//标题
		f.setSize(280,280);
		f.setLayout(null);
		Button b =new Button("Login");///按钮
		b.setBounds((f.getWidth()-100)/2,(f.getHeight()-50)/2,100,50);
		f.add(b);
		f.setBackground(Color.pink);//控制颜色
		f.setVisible(true);
	}

}
//这是一个带按钮可改变背景颜色的窗口


import java.awt.*;
import java.awt.event.*;
public class ScrollDemo {
	public static void main(String args[]){
		Frame f=new Frame("Scrollpanel");//标题
		TextArea t = new TextArea("",10,50,TextArea.SCROLLBARS_NONE);
		ScrollPane sp = new ScrollPane();//生成滚动面板
		sp.add(t);
		f.add(sp);
		f.pack();
		MenuBar mb = new MenuBar();//创建菜单
		f.setMenuBar(mb);
		Menu fm =new Menu("FILE");
		mb.add(fm);
		Menu help =new Menu("HELP");
		mb.add(help);
		mb.setHelpMenu(help);
		Menu opt =new Menu("OPTION");
		mb.add(opt);
		opt.add(new MenuItem("CHANGE TITLE"));
		Menu change = new Menu("CHANGE COLOR");
		opt.add(change);//子菜单
		change.add(new MenuItem("BLUE"));
		change.add(new MenuItem("BLUE"));
		change.add(new MenuItem("RED"));
		change.add(new MenuItem("YELLOW"));
		opt.add(new MenuItem("-"));//分割线		
		CheckboxMenuItem show = new CheckboxMenuItem("SHOW TITLE");
		opt.add(show);
		f.setVisible(true);
	}

}
//带滚动条和菜单的窗口


import java.awt.*;
public class Ui extends java.applet.Applet{
	public void init(){
		add(new Label("Your name: "));//文本框
		add(new TextField(30));//空间大小
		
		add(new Label("Sex: "));//标签
		CheckboxGroup cbg = new CheckboxGroup();
		add(new Checkbox("Male ",cbg,true));
		add(new Checkbox("Female ",cbg,false));
		
		add(new Label("What are you like: "));
		add(new Checkbox("Apple "));
		add(new Checkbox("orange "));
		add(new Checkbox("Strawberry "));
		add(new Checkbox("peach "));
		
		add(new Label("How much do you eat them per week: "));
		Choice c = new Choice();//下拉列表
		c.addItem("less than 1kg ");
		c.addItem("1kg to 3kg ");
		c.addItem("more than 3kg ");
		add(c);
		
		add(new Label("What's your opinion of eating fruit: "));
		add(new TextArea("I think ",3,60));
		add(new Button("OK! "));
		add(new Button("Clear "));
	}
	public void paint(Graphics g){
		
	}
}
//多选择按钮窗口

import java.awt.*;
public class FlowLayoutDemo extends Frame {
	public FlowLayoutDemo(String title){
		super(title);
	}
	public static void main(String[] args){
		FlowLayoutDemo fs  = new FlowLayoutDemo("Border Layout Simple");
		fs.setLayout(new FlowLayout());
		fs.add(new Button("one"));
		fs.add(new Button("two"));
		fs.add(new Button("three"));
		fs.add(new Button("four"));
		fs.setSize(200,200);
		MenuBar mb = new MenuBar();
		fs.setMenuBar(mb);
		Menu fm =new Menu("FILE");
		mb.add(fm);
		Menu help =new Menu("HELP");
		mb.add(help);
		mb.setHelpMenu(help);
		Menu opt =new Menu("OPTION");
		mb.add(opt);
		opt.add(new MenuItem("CHANGE TITLE"));
		Menu change = new Menu("CHANGE COLOR");
		opt.add(change);
		change.add(new MenuItem("BLUE"));
		change.add(new MenuItem("GREEN"));
		change.add(new MenuItem("RED"));
		change.add(new MenuItem("YELLOW"));
		/*Menu change = new Menu("Light");
		change.add(x);
		x.add(new MenuItem("Light blue"));*/
		opt.add(new MenuItem("-"));
		CheckboxMenuItem show = new CheckboxMenuItem("SHOW TITLE");
		//CheckboxMenuItem show = new CheckboxMenuItem("SHOW ME");
		opt.add(show);
		
		fs.setVisible(true);
		
	}
}
//默认的布局管理


import java.awt.*;
public class BorderSimple extends Frame {
	public BorderSimple(String title){
		super(title);
	}
	public static void main(String[] args){
		BorderSimple fs  = new BorderSimple("Border Layout Simple");
		Button north = new Button("北");
		Button south = new Button("南");
		Button west = new Button("西");
		Button east = new Button("东");
		Button center = new Button("中");
		fs.add(north,BorderLayout.NORTH);
		fs.add(south,BorderLayout.SOUTH);
		fs.add(west,BorderLayout.WEST);
		fs.add(east,BorderLayout.EAST);
		fs.add(center,BorderLayout.CENTER);
		fs.setSize(40,40);
		fs.setVisible(true);
	}
	

}
//整体窗口的布局管理


import java.awt.*;
import java.awt.event.*;
public class GridLayOutDemo {
	public static void main (String args []){
		Frame f = new Frame("GridLayOutDemo");
		f.setLayout(new GridLayout(2,3));
		f.add(new Button("1"));
		f.add(new Button("1"));
		f.add(new Button("1"));
		f.add(new Button("1"));
		f.add(new Button("1"));
		f.add(new Button("1"));
		f.pack();
		f.setVisible(true);
	}
}
//网格状布局


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值