package logSFTP;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JPasswordField;
import javax.swing.JPopupMenu;
import javax.swing.JTextField;
public class AddMenu extends JFrame implements ActionListener
{
private JLabel label;
private JLabel label1;
private JLabel label2;
private JLabel label3;
private final JTextField text;
private final JTextField text1;
private final JTextField text2;
private final JTextField text3;
private JButton popupButton;
private JPopupMenu menu;
private JButton ok;
private JButton cancel;
public AddMenu()
{
super("添加页面");
Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
// 下面两行是取得屏幕的高度和宽度
double lx = dimension.getWidth();
double ly = dimension.getHeight();
// 设定窗口出现位置
this.setLocation(new Point((int) (lx / 2) - 150, (int) (ly / 2) - 200));
// 设定窗口大小
this.setSize(360,360);
this.setLayout(null);
this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
label = new JLabel("IP地址");
label.setBounds(60, 25, 100, 30);
this.add(label);
label1 = new JLabel("用户名");
label1.setBounds(60, 65, 100, 30);
this.add(label1);
label2 = new JLabel("密 码");
label2.setBounds(60, 105, 100, 30);
this.add(label2);
label3 = new JLabel("日志文件");
label3.setBounds(60, 145, 100, 30);
this.add(label3);
text = new JTextField();
text.setBounds(120, 25, 120, 25);
this.add(text);
text1 = new JTextField();
text1.setBounds(120, 65, 120, 25);
this.add(text1);
text2 = new JPasswordField();
text2.setBounds(120, 105, 120, 25);
this.add(text2);
text3 = new JTextField();
text3.setBounds(120, 145, 120, 25);
text3.setEditable(false);
this.add(text3);
popupButton = new JButton("请选择");
popupButton.setBounds(250, 145, 80, 25);
popupButton.addActionListener(this);
menu = new JPopupMenu();
String[] textArr = new String[]{"interface","debug","worning"};
for (String str : textArr)
{
JMenuItem item = new JMenuItem(str);
item.addActionListener(this);
menu.add(item);
}
this.add(popupButton);
ok = new JButton("提交");
ok.setBounds(90, 245, 70, 30);
cancel = new JButton("重置");
cancel.setBounds(210, 245, 70, 30);
ok.addActionListener(
new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
// TODO Auto-generated method stub
}
});
cancel.addActionListener(
new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
text.setText("");
text1.setText("");
text2.setText("");
text3.setText("");
}
});
this.add(ok);
this.add(cancel);
this.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent ae) {
if (ae.getSource() == popupButton)
{
menu.show(popupButton, 0, popupButton.getHeight());
}
else
{
JMenuItem item = (JMenuItem) ae.getSource();
text3.setText(item.getText());
}
}
public static void main (String[] args)
{
new AddMenu();
}
}