播放音乐
界面化编程
JFrame
常用初始化设置:
三要素:
frame.setVisible(true);
frame.setSize(450, 400);//宽为450px,长为400px。
frame.setTitle("标题");
常用要素:
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);//设置关闭方式
frame.setLayout(new GridLayout(3,1));//设置布局方式,三行一列
JPanel
作用:弥补布局管理器的不足
常用要素:
JPanel panel=new JPanel();
panel.setLayout(new FlowLayout);//设置流动布局方式
JLabel
作用:标签页
常用使用方式:
JLabel label=new JLabel("这是一个标签");
JButton
作用:按钮
常用使用方式:
JButton button=new JButton("确定");
button.addActionListener(e -> {
JFileChooser JFC = new JFileChooser();//文件选择器
JFC.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);//只选择目录
JFC.showDialog(new JLabel(), "选择目录");//显示目录
File fileInput = JFC.getSelectedFile();//得到选择下的路径文件赋值给fileInput;
doMain.inputPath =fileInput.getAbsolutePath();
input.setText(fileInput.getAbsolutePath());
});
弹出对话框
JOptionPane.showMessageDialog(frame, "对话框内容", "对话框标题", JOptionPane.ERROR_MESSAGE);