allora io ho questo codice ke una volta cliccato su aggiungi mi apre una finestra dove scelgo varie opzioni poi dovrei creare la riga...il problema è ke è la prima volta che uso questo componente e nn è ke mi è molto chiaro...
ecco i due codici ke servono per creare queste righe.
pannello libro giornale
finestra crea contocodice:package school; import javax.swing.*; import java.awt.*; import java.awt.event.*; import javax.swing.JTable; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; /** * * @author Giordano */ public class PDpanel extends JPanel { /** Creates a new instance of PDpanel */ public PDpanel() { JButton addM=new JButton("Aggiungi"); JButton cancelM=new JButton("Cancella"); JButton empty=new JButton("Svuota"); addM.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ createM cm=new createM(); } }); boolean DEBUG = false; String[] columnNames = {"Data", "Descrizione", "Dare", "Avere" }; Object[][] row={}; final JTable t=new JTable(row,columnNames); t.setFillsViewportHeight(true); if (DEBUG) { t.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { printDebugData(t); } }); } JScrollPane scrollPane = new JScrollPane(t); scrollPane.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_ALWAYS ); scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); add(scrollPane); add(addM);add(cancelM);add(empty); } private void printDebugData(JTable table) { int numRows = table.getRowCount(); int numCols = table.getColumnCount(); javax.swing.table.TableModel model = table.getModel(); System.out.println("Value of data: "); for (int i=0; i < numRows; i++) { System.out.print(" row " + i + ":"); for (int j=0; j < numCols; j++) { System.out.print(" " + model.getValueAt(i, j)); } System.out.println(); } System.out.println("--------------------------"); } }
spero ke avete capito cosa voglio fare...cmq se nn si capisce cecherò di spiegarmi mejo!codice:package school; import javax.swing.*; import java.awt.event.*; import java.awt.*; /** * * @author Giordano */ public class createC { static double value; static boolean bo1,bo2; /** Creates a new instance of createM */ public createC() { final JFrame m=new JFrame("Crea mastro"); final JTextField val,valf,name; JButton ok,cancel; final JRadioButton r1,r2,r3,r4; Container cm=m.getContentPane(); final JPanel cmp=new JPanel(); ButtonGroup bg = new ButtonGroup(); ButtonGroup bg2=new ButtonGroup(); cm.add(cmp); name=new JTextField("Nome conto",20); val=new JTextField("Importo",20); valf=new JTextField("Formula",20); val.setEnabled(false); valf.setEnabled(false); r1=new JRadioButton(); r2=new JRadioButton(); bg2.add(r1); bg2.add(r2); r3=new JRadioButton("Dare"); r4=new JRadioButton("Avere"); bg.add(r3); bg.add(r4); r1.addItemListener(new ItemListener(){ public void itemStateChanged(ItemEvent e){ val.setEnabled(true); valf.setEnabled(false); } }); r2.addItemListener(new ItemListener(){ public void itemStateChanged(ItemEvent e){ valf.setEnabled(true); val.setEnabled(false); } }); ok=new JButton("ok"); ok.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ m.setVisible(false); if (r1.isSelected()){ value=Double.parseDouble(val.getText().trim()); } if(r2.isSelected()){ try{ String s=valf.getText(); org.nfunk.jep.JEP myParser = new org.nfunk.jep.JEP(); myParser.parseExpression(s); value= myParser.getValue(); } catch(Exception exc){ exc.printStackTrace(); } } String nameC=name.getText(); if(r3.isSelected()){ bo1=true; bo2=false; System.out.println(nameC+" Dare: "+value+" euro"); } if(r4.isSelected()){ bo2=true; bo1=false; System.out.println(nameC+" Avere: "+value+" euro"); } M m=new M(nameC,bo1,bo2,value); //cmp.add(m); } }); cancel=new JButton("annulla"); cancel.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ m.setVisible(false); } }); cmp.setLayout(new FlowLayout()); cmp.add(name); cmp.add(r3);cmp.add(r4); cmp.add(r1);cmp.add(val); cmp.add(r2);cmp.add(valf); cmp.add(ok);cmp.add(cancel); m.pack(); m.setResizable(false); m.setLocationRelativeTo(null); m.setVisible(true); } }![]()

Rispondi quotando