好吧,我写了这个代码片作为一个初学者在java学习视频/学校,我有一些问题。从菜单项/菜单栏和声音播放器Java退出按钮
1 =>为什么文件>退出按钮不工作,有一个小箭头,就好像有一些孩子的?大退出按钮使用相同的功能。 我从这里获得灵感:http://www.youtube.com/watch?src_vid=FB_wJpIdA8k&feature=iv&annotation_id=annotation_40248&v=dwLkDGm5EBc
2 =>我该如何让这个按钮更小?调整大小时它会更大。
3 =>有谁知道一个简单的声音播放器库?所以当我按下该按钮来播放声音?我尝试了一些网络示例,如http://www.developer.com/java/other/article.php/2173111/Java-Sound-Playing-Back-Audio-Files-using-Java.htm,不知道如何使它变得简单,并在SoundPlay(sound.au)等各处使用。
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
public class form4
{
public static void main(String[] args)
{
// Frame
JFrame frame = new JFrame("Menu");
frame.setSize(300,300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Just create menubar
JMenuBar menubar = new JMenuBar();
frame.setJMenuBar(menubar);
// Add an JMenu
JMenu file = new JMenu("File");
menubar.add(file);
// Add an JMenuItem
JMenuItem exit = new JMenu("Exit");
file.add(exit);
exit.addActionListener(new exitApp());
// Add an JMenu
JMenu help = new JMenu("Help");
menubar.add(help);
// Add an JMenuItem
JMenuItem about = new JMenuItem("About");
help.add(about);
// Add an JButton
JButton exitButton= new JButton("Exit!");
frame.add(exitButton);
exitButton.addActionListener(new exitApp());
exitButton.setSize(40,40);
frame.setVisible(true);
}
// Exit app
static class exitApp implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
}
}
谢谢!
参见[使用菜单](HTTP:// docs.oracle.com/javase/tutorial/uiswing/components/menu.html)有关子菜单。 – trashgod 2012-01-03 03:03:27
另请参阅[初始线程](http://download.oracle.com/javase/tutorial/uiswing/concurrency/initial.html)。 – trashgod 2012-01-03 03:04:18