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

📄 words.java

📁 实现文件的由大变小
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
public class words extends Frame implements ActionListener{
int i=0;
Label res;
Button b1,b2;
String word[]={"zero","one","two","three","four","five","six","seven","eight"};
public words(){
   super("欢迎您使用单词浏览器");
   b1=new Button("上一个");
   b2=new Button("下一个");
   res=new Label(word[0]);//显示结果的标签
   setLayout(new FlowLayout());//指定按流式布局排列部件
   add(b1);
   add(res);
   add(b2);
  this.addWindowListener(new WinAdpt());
  b1.addActionListener(this);//通过addActionListener方法为按钮注册一个事件监听处理者
  b2.addActionListener(this);//通过addActionListener方法为按钮注册一个事件监听处理者
  setSize(400,100);//设置窗体大小
  show();//显示窗体
}
public void actionPerformed(ActionEvent e)	{
	if(e.getSource()==b1){//获取事件对象名	
		i--;
		if(i<0)	i=8;			
                res.setText(word[i]);
		}
		else if(e.getSource()==b2){				
               i++;			
               if(i>8)	i=0;
	       res.setText(word[i]);
		}
	}
		
class WinAdpt extends WindowAdapter{
	public void windowClosing(WindowEvent e)	{
		Window w=e.getWindow();
                w.dispose();
}
}
public static void main (String args[]){
             new words();
   }
}

 
   

   
   

⌨️ 快捷键说明

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