首页上一页 1 下一页尾页 3 条记录 1/1页
编写一个基本用药管理界面时,想通过查询按钮根据条件查询,但一直提示JTextField tfbianhao.gettext()需要用final修饰,可final修饰后又不能实时调用文本框里的内容了,如何解决?
public JbDrugInfor() { //addAction(); setTitle("基本用药目录查询"); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setSize(1147, 400); // 设置窗体大小 setResizable(false); // 将窗体放于屏幕正中 Toolkit tool = Toolkit.getDefaultToolkit(); Dimension d = tool.getScreenSize(); setLocation((d.width - getWidth()) / 2, (d.height - getHeight()) / 2); Container c = getContentPane(); // 获取窗体容器 c.setLayout(new BorderLayout()); c.setBackground(null); JPanel p1 = new JPanel(); p1.setLayout(new BorderLayout()); p1.setLayout(null); c.add(p1); final JPanel p2 = new JPanel(); p2.setLayout(null); p2.setBounds(0, 80, 1170, 300); p1.add(p2); JLabel title = new JLabel("基本用药目录管理", JLabel.CENTER); title.setFont(new Font("宋体", Font.BOLD, 30)); title.setBounds(0, 0, 1170, 50); p1.add(title); JPanel p3 = new JPanel(); p3.setLayout(null); p3.setBounds(0, 50, 1200, 30); p3.setBorder(BorderFactory.createLineBorder(Color.GRAY, 1)); p3.setBackground(Color.LIGHT_GRAY); p1.add(p3); JLabel bianhao = new JLabel("编号:",JLabel.RIGHT); bianhao.setFont(new Font("仿宋",Font.BOLD,16)); bianhao.setBounds(10, 0, 60, 30); p3.add(bianhao); JTextField tfbianhao = new JTextField(null, 12); tfbianhao.setFont(new Font("仿宋", Font.PLAIN, 15)); tfbianhao.setBounds(70, 5, 50, 20); p3.add(tfbianhao); JLabel tym = new JLabel("药品名称:",JLabel.RIGHT); tym.setFont(new Font("仿宋",Font.BOLD,16)); tym.setBounds(140, 0, 90, 30); p3.add(tym); JTextField tfypmc = new JTextField(null, 12); tfypmc.setFont(new Font("仿宋", Font.PLAIN, 15)); tfypmc.setBounds(230, 5, 120, 20); p3.add(tfypmc); JLabel scs = new JLabel("生产商:",JLabel.RIGHT); scs.setFont(new Font("仿宋",Font.BOLD,16)); scs.setBounds(360, 0, 80, 30); p3.add(scs); JTextField tfscs = new JTextField(null, 12); tfscs.setFont(new Font("仿宋", Font.PLAIN, 15)); tfscs.setBounds(440, 5, 80, 20); p3.add(tfscs); JLabel lb = new JLabel("类别:",JLabel.RIGHT); lb.setFont(new Font("仿宋",Font.BOLD,16)); lb.setBounds(540, 0, 60, 30); p3.add(lb); JTextField tflb = new JTextField(null, 12); tflb.setFont(new Font("仿宋", Font.PLAIN, 15)); tflb.setBounds(600, 5, 80, 20); p3.add(tflb); JLabel jx = new JLabel("剂型:",JLabel.RIGHT); jx.setFont(new Font("仿宋",Font.BOLD,16)); jx.setBounds(700, 0, 60, 30); p3.add(jx); JTextField tfjx = new JTextField(null, 12); tfjx.setFont(new Font("仿宋", Font.PLAIN, 15)); tfjx.setBounds(760, 5, 80, 20); p3.add(tfjx); JLabel ky = new JLabel("可用:",JLabel.RIGHT); ky.setFont(new Font("仿宋",Font.BOLD,16)); ky.setBounds(850, 0, 60, 30); p3.add(ky); JCheckBox option = new JCheckBox(); option.setSelected(true); option.setBounds(910, 4, 30, 25); option.setBackground(Color.LIGHT_GRAY); p3.add(option); JButton b1 = new JButton("查询"); b1.setFont(new Font("宋体", Font.BOLD, 14)); b1.setBounds(970, 4, 70, 22); b1.setBackground(new Color(247, 239, 93)); p3.add(b1); b1.addActionListener (new ActionListener() { public void actionPerformed(ActionEvent e) { String bh = tfbianhao.getText().trim(); String sql = "select * from jbdrug where jbid like '"+bh+"' order by namepy" ; table.setBorder(new LineBorder(new Color(0, 0, 0))); head=new String[] { "序号","药品编号", "通 用 名", "商品名","规 格","生产厂家","类 别", "剂 型", "基本单位", "包装单位", "库存上限","库存下限","别 名","是否可用" }; DefaultTableModel tableModel=new DefaultTableModel(queryData(sql),head){ public boolean isCellEditable(int row, int column) { return false; } };