2012-09-26 24 views
1

我有点问题,我的程序的功能是显示选定的项目 我点击了JList区域,点击确定按钮后,收据将从 JtextArea与总,税和物品,我一直在尝试它,但收据w /总,税和物品(JTextArea)不会 出来。Jtextarea不会出来

+0

没有人理解你所需要的。 –

+0

恐怕很难理解你的问题。你有没有工作的代码?如果是这样,请与我们分享,我们可以帮助您。 –

回答

4

JList区域和点击确定按钮后,一个收据将从JtextArea与总额,税款和项目出来,我一直在尝试它,但收据W /总计,税收和项目( JTextArea)不会出来。以这种形式

  1. 问题不回答的,张贴SSCCE

  2. 也许JTextArea是不恰当的JComponent用于示出a receipt will come out from the JtextArea with the total, tax and items,更好可以是使用另一JTable(或JList),用于显示total, tax and items

  3. 是否只有几个字段用于计算或显示total, tax and items的使用JFormattedTextFiedlsNumber Formatter以避免任何解析字符串到数字或反之亦然

3

检查下面的示例代码的JList:

public class PhilosophersJList extends JFrame { 

private DefaultListModel philosophers; 
private JList list; 

public PhilosophersJList() 
    { 
    super("Favorite Philosophers"); 

    // create a DefaultListModel to store philosophers 
    philosophers = new DefaultListModel(); 
    philosophers.addElement("Socrates"); 
    philosophers.addElement("Plato"); 
    philosophers.addElement("Aristotle"); 
    philosophers.addElement("St. Thomas Aquinas"); 
    philosophers.addElement("Soren Kierkegaard"); 
    philosophers.addElement("Immanuel Kant"); 
    philosophers.addElement("Friedrich Nietzsche"); 
    philosophers.addElement("Hannah Arendt"); 

    // create a JList for philosophers DefaultListModel 
    list = new JList(philosophers); 

    // allow user to select only one philosopher at a time 
    list.setSelectionMode(
    ListSelectionModel.SINGLE_SELECTION); 

    // create JButton for adding philosophers 
    JButton addButton = new JButton("Add Philosopher"); 
    addButton.addActionListener(
     new ActionListener() { 

     public void actionPerformed(ActionEvent event) 
      { 
      // prompt user for new philosopher's name 
      String name = JOptionPane.showInputDialog(
      PhilosophersJList.this, "Enter Name"); 

      // add new philosopher to model 
      philosophers.addElement(name); 
     } 
    } 
    ); 

    // create JButton for removing selected philosopher 
    JButton removeButton = 
    new JButton("Show Details"); 

    removeButton.addActionListener(
     new ActionListener() { 

     public void actionPerformed(ActionEvent event) 
      { 
       String details = JOptionPane.showInputDialog(PhilosophersJList.this, "Tax :", list.getSelectedValue()); 
     philosophers.addElement(details); 

     } 
    } 
    ); 

    // lay out GUI components 
    JPanel inputPanel = new JPanel(); 
    inputPanel.add(addButton); 
    inputPanel.add(removeButton); 

    Container container = getContentPane(); 
    container.add(list, BorderLayout.CENTER); 
    container.add(inputPanel, BorderLayout.NORTH); 

    setDefaultCloseOperation(EXIT_ON_CLOSE); 
    setSize(400, 300); 
    setVisible(true); 

} // end PhilosophersJList constructor 

// execute application 
public static void main(String args[]) 
    { 
    new PhilosophersJList(); 
} 
}