JTextField.setText()里的值能否从INI文件或其他文件里自动读取

JTextField.setText()里的值能否从INI文件或其他文件里自动读取
初学的时候采用定值,现在想实现自动从文件获取,该如何实现

final JTextField lvfjt3=new JTextField();
			final JTextField lvfjt4=new JTextField();
			final JTextField lvfjt5=new JTextField();
			final JTextField lvfjt6=new JTextField();
			lvfjt3.setColumns(7);
			lvfjt4.setColumns(7);
			lvfjt5.setColumns(7);
			lvfjt6.setColumns(7);
			lvfjt3.setText("0.5");
			lvfjt4.setText("10");
			lvfjt5.setText("25");
			lvfjt6.setText("10");
			
改进以下代码,让错误出现三次弹出冻结信息并关闭窗体。denglu.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int count = 0; String inputzh = zhanghu.getText(); boolean bl = true; try { new Mysql(); bl = Mysql.jujle(inputzh); } catch (ClassNotFoundException e1) { // TODO 自动生成的 catch 块 e1.printStackTrace(); } catch (SQLException e1) { // TODO 自动生成的 catch 块 e1.printStackTrace(); } System.out.println(bl); if (bl) { try { System.out.println(inputzh); new GUI2(inputzh); jf.dispose(); } catch (Exception e1) { // TODO 自动生成的 catch 块 e1.printStackTrace(); } } else { ImageIcon titleIcon = new ImageIcon("F:\\ATM.png"); JDialog jDialog = new JDialog(jf, "错误", true); jDialog.setSize(400, 200); jDialog.setLocation(575, 400); JTextField jTextField = new JTextField("您的账号和密码输入有误!请重新输入。"); jTextField.setHorizontalAlignment(JTextField.CENTER); jTextField.setEditable(false); jTextField.setSelectedTextColor(Color.black); jDialog.add(jTextField); jDialog.setIconImage(titleIcon.getImage()); jTextField.setVisible(true); jDialog.setVisible(true); count++; if (count == 3) { ImageIcon titleIcon1 = new ImageIcon("F:\\ATM.png"); JDialog jDialog1 = new JDialog(jf, "错误", true); jDialog.setSize(400, 200); jDialog.setLocation(575, 400); JTextField jTextField1 = new JTextField("您的账号已冻结!请联系人工处理。"); jTextField.setHorizontalAlignment(JTextField.CENTER); jTextField.setEditable(false); jTextField.setSelectedTextColor(Color.black); jDialog.add(jTextField1); jDialog.setIconImage(titleIcon1.getImage()); jTextField.setVisible(true); jDialog.setVisible(true); jf.setDefaultCloseOperation(3); System.exit(0); } else { jpl.repaint(); } } } });
05-31
public class Calculator extends JFrame { private JPanel result, button; private JLabel show; private JButton CLR, add, minus, Multiply, divide; private JTextField field; private Double answer; private String number; public Calculator() { super("Calculator"); this.setLocationRelativeTo(null);// set up window this.setResizable(false); this.setDefaultCloseOperation(EXIT_ON_CLOSE); this.setSize(600, 200); result = new JPanel(); answer = 0.0 ; show = new JLabel(Double.toString(answer), SwingConstants.RIGHT);// let the result at the right of the field result.add(show); JTextField filed = new JTextField(Double.toString(answer));// setup the size of the text field filed.setColumns(6); filed.setHorizontalAlignment(JTextField.RIGHT); button = new JPanel(); button.setLayout(new GridLayout(1, 5)); CLR = new JButton("CLR");// add the buttons of calculation. add = new JButton("+"); minus = new JButton("-"); Multiply = new JButton("*"); divide = new JButton("/"); button.add(CLR); button.add(add); button.add(minus); button.add(Multiply); button.add(divide); CLR.addActionListener(e -> {// clear answer = 0.0; show.setText(Double.toString(answer)); field.setText(" "); }); add.addActionListener(e -> {// add number = field.getText(); if (!number.equals(null)) { double value = Double.parseDouble(number); answer += value; show.setText(Double.toString(answer)); field.setText(""); } }); minus.addActionListener(e -> {// minus number = field.getText(); if (!number.equals("")) { double value = Double.parseDouble(number); answer -= value; show.setText(Double.toString(answer)); field.setText(""); } }); Multiply.addActionListener(e -> {// multiply number = field.getText(); if (!number.equals("")) { double value = Double.parseDouble(number); answer *= value; show.setText(Double.toString(answer)); field.setText(""); } }); divide.addActionListener(e -> {// divide number = field.getText(); if (!number.equals("")) { double value = Double.parseDouble(number); answer /= value; show.setText(Double.toString(answer)); field.setText(""); } }); add(button); add(field); add(result); this.setLayout(new GridLayout(3, 1)); this.setVisible(true); }
05-29
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值