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

📄 testmenu.java

📁 一些简单的java程序。老师很认真
💻 JAVA
字号:
package com.test;

import java.awt.*; 
import java.awt.event.*; 
import java.io.*; 
import com.resource.*;
public class TestMenu extends Frame implements ActionListener 
{ 
TextArea ta; 
Button b1,b2; 
Dialog md; 
MenuItem open,save,myexit,open1,save1; 
MenuItem copy,palse; 
CheckboxMenuItem bold,ita; 
MenuBar mb; 
public PopupMenu popm; 
public void createmenu() 
{ 
mb=new MenuBar(); 
Menu m1=new Menu("文件"); 
Menu m2=new Menu("编辑"); 
Menu m3=new Menu("字体"); 
mb.add(m1);mb.add(m2);m2.add(m3); 

open=new MenuItem("打开"); 
open.addActionListener(this); 
save=new MenuItem("保存"); 
myexit=new MenuItem("退出"); 
m1.add(open);m1.add(save);m1.add(myexit); 

copy=new MenuItem("复制"); 
palse=new MenuItem("粘贴"); 
bold=new CheckboxMenuItem("加粗"); 
ita=new CheckboxMenuItem("倾斜"); 
m2.add(copy);m2.add(palse); 
m3.add(bold);m3.add(ita); 
popm=new PopupMenu (); 
open1=new MenuItem("打开"); 
open1.addActionListener(this); 
save1=new MenuItem("保存"); 
popm.add(open1);popm.add(save1); 
ta.add(popm); 
ta.addMouseListener(new MyMouseEvent(this)); 

} 

public TestMenu () 
{ 
addWindowListener(new WindowAdapter(){ 
public void windowClosing(WindowEvent e) 
{ 
dispose(); 
System.exit(0); 
} 
}); 

ta=new TextArea(10,30); 
b1=new Button("弹出对话框"); 
b2=new Button("隐藏对话框"); 
b1.addActionListener(this); 
b2.addActionListener(this); 
add(ta,BorderLayout.CENTER); 
Panel p1=new Panel(); 
p1.add(b1); 
p1.add(b2); 
add(p1,BorderLayout.SOUTH); 
setVisible(true); 
setSize(400,300); 
md=new Dialog(this,"对话框"); 
md.add(new Label("这是一个对话框")); 
md.setSize(100,60); 
md.addWindowListener(new WindowAdapter(){ 
public void windowClosing(WindowEvent e) 
{ 
md.setVisible(false); 
} 
}); 
pack(); 
createmenu(); 
setMenuBar(mb); 
} 
public void actionPerformed(ActionEvent e) 
{ 
if(e.getSource()==b1) 
md.setVisible(true); 


if(e.getSource()==b2) 
md.setVisible(false); 
if(e.getActionCommand()=="打开") 
try{ openfile();}catch(IOException ex){} 
} 
public void openfile() throws IOException 
{ 
FileDialog fd=new FileDialog(this,"aaa",FileDialog.LOAD); 
fd.setVisible(true); 
FileInputStream fis=new FileInputStream( fd.getDirectory()+fd.getFile()); 
String s=""; 
int n=0; 
while((n=fis.read())!=-1) 
ta.append(""+(char)n); 
fis.close(); 
} 
public static void main(String []args) 
{ 
TestMenu tw=new TestMenu(); 
} 
}

⌨️ 快捷键说明

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