2012-09-26 28 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(); 
} 
}