⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 awtdemo.java

📁 一个java的源文件
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
public class awtDemo
{
	private Frame f=new Frame("组件事件的用法");
	private Button b_first=new Button("第一张");
	private Button b_last=new Button("最后一张");
	private Button b_next=new Button("下一张");
	private Button b_previous=new Button("前一张");
	private Label l1=new Label("这是第一页",Label.CENTER);
	private Label l2=new Label("这是第二页",Label.CENTER);
	private Label l3=new Label("这是第三页",Label.CENTER);
	private Label l4=new Label("这是第四页",Label.CENTER);
	private Label l5=new Label("这是第五页",Label.CENTER);
	private Label l6=new Label("这是第六页",Label.CENTER);
	private TextField tf=new TextField(3);
	private Label ll=new Label("请输入要显示的页号:");
	private Panel pc=new Panel();
	private CardLayout c=new CardLayout();
	private int select=0;
	Font ft=new Font("Serif",Font.ITALIC,28);
	public static void main(String args[])
	{
		awtDemo that=new awtDemo();
		that.go();
	}
	void go()
	{
		f.setLayout(new BorderLayout(0,10));
		Panel pl=new Panel();
		b_first.addActionListener(new ButtonHandler(1));
		b_next.addActionListener(new ButtonHandler(2));
		b_previous.addActionListener(new ButtonHandler(3));
		b_last.addActionListener(new ButtonHandler(4));
		f.add("Center",pc);
		pc.setLayout(c);
		pc.add(l1,"page1");
		pc.add(l2,"page2");
		pc.add(l3,"page3");
		pc.add(l4,"page4");
		pc.add(l5,"page5");
		pc.add(l6,"page6");
		f.add("South",pl);
		pl.setLayout(new FlowLayout());
		pl.add(b_first);
		pl.add(b_next);
		pl.add(b_previous);
		pl.add(b_last);
		pl.add(ll);
		pl.add(tf);
		tf.addTextListener(new TextHandler());
		f.addWindowListener(new WindowHandler());	
		l1.setFont(ft);
		l3.setFont(ft);
		l5.setFont(ft);
		l6.setFont(ft);
		l2.setBackground(Color.blue);
		l4.setBackground(Color.red);
		f.setSize(450,250);
		f.setResizable(true);
		f.setVisible(true);
	}
	class ButtonHandler implements ActionListener
	{
		private int sel;
		ButtonHandler(int select)
		{
			this.sel=select;
		}
		public void actionPerformed(ActionEvent e)
		{
			switch(sel)
			{
				case 1:c.first(pc);break;
				case 2:c.next(pc);break;
				case 3:c.previous(pc);break;
				case 4:c.last(pc);break;
			}
		}
	}
	class TextHandler implements TextListener
	{
		public void textValueChanged(TextEvent e)
		{
			c.show(pc,"page"+tf.getText());
		}
	}
	class WindowHandler extends WindowAdapter
	{
		public void windowClosing(WindowEvent e)
		{
			System.exit(1);
		}
	}
}	
	
	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -