📄 setwindow.java
字号:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class SetWindow extends JFrame implements ActionListener {
private JButton search,save;
private JTextField path;
public SetWindow() {
this.setUndecorated(true);
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
this.setLocation((screen.width-400)/2,(screen.height-100)/2);
JPanel panel = new JPanel();
panel.setBackground(Color.PINK);
panel.setPreferredSize(new Dimension(400,100));
panel.setLayout(new BoxLayout(panel,BoxLayout.Y_AXIS));
panel.add(Box.createRigidArea(new Dimension(0,10)));
JPanel panel1 = new JPanel();
panel1.setBackground(Color.PINK);
panel1.setLayout(new BoxLayout(panel1,BoxLayout.X_AXIS));
JLabel label = new JLabel("设置路径:");
path = new JTextField(20);
panel1.add(label);
panel1.add(path);
panel.add(panel1);
panel.add(Box.createRigidArea(new Dimension(0,10)));
JPanel panel2 = new JPanel();
panel2.setBackground(Color.PINK);
search = new JButton("浏览...");
search.addActionListener(this);
save = new JButton("保存路径");
save.addActionListener(this);
panel2.add(search);
panel2.add(save);
panel.add(panel2);
this.getContentPane().add(panel);
this.pack();
this.setVisible(true);
}
public void actionPerformed(ActionEvent event) {
Object source = event.getSource();
if(source==search) {
}
if(source ==save) {
if(path.getText().length()==0) {
JOptionPane.showMessageDialog(this,"路径不能为空");
}
else {
JOptionPane.showMessageDialog(this,"路径已保存");
this.dispose();
new MainWindow();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -