?
package guidemo5;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
public class Demo_MusicPlayer {
public static void main(String[] args) {
WindowShow demo = new WindowShow();
demo.init();
}
}
class WindowShow{
private int width = 600;
private int height = 500;
private Toolkit tool = Toolkit.getDefaultToolkit();
private Dimension dimension = tool.getScreenSize();
private int scnWidth = dimension.width;
private int scnHeight = dimension.height;
private JFrame frame = new JFrame("音乐播放器");
private JTextArea textArea = new JTextArea(20,20);
private JScrollPane scrollPane = new JScrollPane(textArea);
private JToolBar toolBar = new JToolBar("工具条",JToolBar.HORIZONTAL);
// private JButton pre = new JButton("上一曲");
// private JButton stop = new JButton("暂停播放");
// private JButton next = new JButton("下一曲");
private Action pre = new AbstractAction("上一曲") {
@Override
public void actionPerformed(ActionEvent e) {
textArea.append("上一曲\n");
}
};
private Action stop = new AbstractAction("暂停播放") {
@Override
public void actionPerformed(ActionEvent e) {
textArea.append("暂停播放\n");
}
};
private Action next = new AbstractAction("下一曲") {
@Override
public void actionPerformed(ActionEvent e) {
textArea.append("下一曲\n");
}
};
public void init(){
frame.setBounds((scnWidth-width)/2,(scnHeight-height)/2,width,height);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
toolBar.add(pre);
toolBar.addSeparator();
toolBar.add(stop);
toolBar.addSeparator();
toolBar.add(next);
toolBar.setFloatable(true);
frame.add(scrollPane);
frame.add(toolBar,BorderLayout.NORTH);
frame.setVisible(true);
}
}
|