java语言基础代码字典 java字典用法( 三 )


JMenu helpMenu = new JMenu("Help");
helpMenu.setMnemonic('H');
aboutItem = new JMenuItem("About");
aboutItem.setMnemonic('A');
aboutItem.addActionListener(new
AbstractAction(){
public void actionPerformed(ActionEvent event)
{
new guanyu();
}
});
helpMenu.add(aboutItem);
menubar = new JMenuBar();
setJMenuBar(menubar);
menubar.add(fileMenu);
menubar.add(editMenu);
menubar.add(helpMenu);
//工具栏
label = new JLabel("请输入:");
text1= new JTextField("");
selectButton = new JButton("查询");
//工具栏查询监听器
selectButton.addActionListener(new
AbstractAction(){
public void actionPerformed(ActionEvent event)
{
if(text1.getText().equals(""))
text2.setText("没有输入查询内容!请重新输入?。。?);
else text2.setText(new select().jselect(text1.getText().trim()));
}
});
//工具栏增加监听器
addButton = new JButton("增加");
addButton.addActionListener(new
AbstractAction(){
public void actionPerformed(ActionEvent event)
{
if(text1.getText().equals(""))
text2.setText("没有输入内容!请重新增加?。。?);
else
{
String s=text1.getText().trim();
String s1=text2.getText().trim();
text2.setText(new add().jadd(text1.getText().trim(),text2.getText().trim()));
text2.append(s+"\n"+s1+";"+""+"//"+"该内容已增加?。。?);
}
}
});
//工具栏修改监听器
updateButton = new JButton("修改");
updateButton.addActionListener(new
AbstractAction(){
public void actionPerformed(ActionEvent event)
{
if(text1.getText().equals(""))
text2.setText("没输入所要修改的内容!请重新输入?。。。?);
else{
String s=text1.getText().trim();
text2.setText(new update().jupdate(text1.getText().trim(),
text2.getText().trim()));
text2.append(s+""+"//"+"该内容已修改?。。?);
}
}
});
//工具栏删除监听器
deleteButton = new JButton("删除");
deleteButton.addActionListener(new
AbstractAction(){
public void actionPerformed(ActionEvent event)
{
if(text1.getText().equals(""))
text2.setText("没输入所要删除的内容!请重新输入?。。。?);
else{
String s=text1.getText().trim();
text2.setText(new delete().jdelete(text1.getText().trim()));
text2.append(s+""+"//"+"该内容已删除?。。?);
}
}
});
soundButton = new JButton("读音");
soundButton.addActionListener(new
AbstractAction(){
public void actionPerformed(ActionEvent event)
{
JavaSoundAudioClipplayer;
try{
strsound = text2.getText().trim();
FileInputStreamff=new FileInputStream("sound//"+strsound+".wav");
player = new JavaSoundAudioClip(ff);
player.play();
}
catch(Exceptione){
System.out.println("error");
e.printStackTrace();
}
}
});
//万年历
dateButton = new JButton("万年历");
dateButton.addActionListener(new
AbstractAction(){
public void actionPerformed(ActionEvent event)
{
new calendar();
}
});
toolbar = new JToolBar();
add(toolbar,BorderLayout.NORTH);
toolbar.add(label);
toolbar.add(text1);
toolbar.add(selectButton);
toolbar.add(addButton);
toolbar.add(updateButton);
toolbar.add(deleteButton);
toolbar.add(soundButton);
toolbar.add(dateButton);
text2 = new JTextArea(8,40);
text2.setLineWrap(true);
JScrollPane scroll = new JScrollPane(text2);
add(scroll,BorderLayout.CENTER);
//快捷菜单 剪切,复制,粘贴
JPopupMenu popup= new JPopupMenu();
text2.setComponentPopupMenu(popup);

推荐阅读