📄 prefference.java
字号:
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.io.*;
import java.util.*;
public class Prefference extends JDialog{
JPanel up,center,down,over;
JLabel antnum,defaultDirect;
JTextField directText;
JComboBox numBox;
JButton ok,cancel;
JScrollPane sp;
Container contentPane;
Listener listener;
public Prefference(JFrame f){
super(f,"Prefference...");
init();
}
public void init(){
String[] items={"1","2","3","4","5","6","7","8"};
listener=new Listener();
contentPane=getContentPane();
up=new JPanel();
over=new JPanel();
center=new JPanel();
down=new JPanel();
antnum=new JLabel("Ants Num:");
defaultDirect=new JLabel("Default Directory:");
directText=new JTextField(20);
directText.setText("c:\\download");
numBox=new JComboBox(items);
// numBox.setVisibleRowCount(1);
numBox.setSelectedIndex(4);
sp=new JScrollPane(numBox);
ok=new JButton("OK");
ok.addActionListener(listener);
cancel=new JButton("Cancel");
cancel.addActionListener(listener);
over.setLayout(new FlowLayout(1));
up.setLayout(new FlowLayout(2));
up.add(defaultDirect);
up.add(directText);
center.setLayout(new FlowLayout(2));
center.add(antnum);
center.add(sp);
//down.setLayout(new FlowLayout(2));
down.add(ok);
down.add(cancel);
over.add(up);
over.add(center);
//over.add(down,BorderLayout.SOUTH);
contentPane.add(over,BorderLayout.CENTER);
contentPane.add(down,BorderLayout.SOUTH);
}
class Listener implements ActionListener{
public void actionPerformed(ActionEvent e){
String command=e.getActionCommand();
if(command=="OK"){
Utility.antNum=Integer.parseInt(numBox.getSelectedItem().toString());
Utility.defaultDirectory=directText.getText();
System.out.println(Utility.antNum);
System.out.println(Utility.defaultDirectory);
dispose();
}
else if(command=="Cancel"){
dispose();
}
}
}
public void center(){
Dimension screenSize,size;
screenSize=Toolkit.getDefaultToolkit().getScreenSize();
size=this.getSize();
if(size.height > screenSize.height){
size.height=screenSize.height;
}
if(size.width >screenSize.width){
size.width=screenSize.width;
}
this.setLocation((screenSize.width - size.width)/2,(screenSize.height - size.height)/2);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -