新手请教高手帮忙改写脚本

yan00008 2014-11-20 10:11:00



我的代码:
package run;
import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class JComboBoxModelTest extends JFrame {

private static final long serialVersionUID = 1L;
JComboBox<String> jc = new JComboBox<>(new MyComboBox());
JLabel jl = new JLabel("请选择产品类型:");
JTextField jt1 = new JTextField("aaa",10);
final JButton jb1=new JButton("清除");
JTextField jt2 = new JTextField("aaa",10);
final JButton jb2=new JButton("清除");
JTextField jt3 = new JTextField("aaa",10);
final JButton jb3=new JButton("清除");
final JButton jb4=new JButton("绑定IP");

public JComboBoxModelTest() {
setSize(new Dimension(800, 500));
setVisible(true);
setTitle("在窗口中设置下拉列表框");
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
Container cp = getContentPane();
cp.setLayout(new FlowLayout(0));
cp.add(jl);
cp.add(jc);
cp.add(jt1);
cp.add(jb1);
cp.add(jt2);
cp.add(jb2);
cp.add(jt3);
cp.add(jb3);
cp.add(jb4);
jt1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
// TODO 自动生成方法存根
jt1.setText("触发事件");
}
});
jb1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
jt1.setText("");
jt1.requestFocus();
}
});
jt2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
// TODO 自动生成方法存根
jt2.setText("触发事件");
}
});
jb2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
jt2.setText("");
jt2.requestFocus();
}
});
jt3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
// TODO 自动生成方法存根
jt3.setText("触发事件");
}
});
jb3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
jt3.setText("");
jt3.requestFocus();
}
});

}

public static void main(String[] args) {
new JComboBoxModelTest();
}
}

class MyComboBox extends AbstractListModel<String> implements ComboBoxModel<String> {
private static final long serialVersionUID = 1L;
String selecteditem = null;
String[] test = { "A", "B", "C", "D" };

public String getElementAt(int index) {
return test[index];
}

public int getSize() {
return test.length;
}

public void setSelectedItem(Object item) {
selecteditem = (String) item;
}

public Object getSelectedItem() {
return selecteditem;
}

public int getIndex() {
for (int i = 0; i < test.length; i++) {
if (test[i].equals(getSelectedItem()))
return i;
}
return 0;
}
}
...全文
164 3 打赏 收藏 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
yan00008 2014-11-24
  • 打赏
  • 举报
回复
u010005508:你好,我执行了,但是感觉不对,路由没加上,后来我改成 "ping www.163.com",无需输入了,但是不知道能弹出DOS窗口,看执行结果,谢谢高手
Super丶King 2014-11-21
  • 打赏
  • 举报
回复
java窗体程序,辣么牛。
highnewrain 2014-11-21
  • 打赏
  • 举报
回复
绑定IP按钮加个事件相应呗,然后调用CMD命令执行,如下可参考:
jb4.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				String strCmd="cmd /c route add "+jt1.getText()+" mask "+jt2.getText()+" "+jt3.getText();
				JOptionPane.showMessageDialog(null, strCmd);
				try {
					Runtime.getRuntime().exec(strCmd);
				} catch (IOException ex) {
					ex.printStackTrace();
				}
			}
		});

62,620

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧