Kapws Δημοσ. 22 Μαΐου 2011 Δημοσ. 22 Μαΐου 2011 Καλησπέρα, έχω αυτό το κώδικα και για αρχή θα ήθελα να κάνει copy ότι κάνει το jtextfield στα strings του jcombobox με χρήση streams. > package superm; import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; class SuperM extends JFrame{ JMenuBar menuBar; JMenu fileMenu; JMenuItem fileOpen,fileSave,fileCopy; // MenuItemHandler mhandler; JFileChooser chooser; File file; FileReader input; FileWriter output; BufferedReader reader; GridLayout gl; JPanel pl1,p12,p13; JTextArea textArea1; JTextField text1 = new JTextField(" ", 8);//eidos JTextField text2= new JTextField(" ", 8);//posotita JLabel Eidos = new JLabel("Eidos "); JLabel Posotita = new JLabel("Posotita"); String[] eidos= {" "}; String[] posotita = {" "}; String emfanisi[]; JComboBox combo1;//eidos JComboBox combo2;//posotita JComboBox combo3;//enfanisi public SuperM() { super("Carrefour"); MenuItemHandler mhandler=new MenuItemHandler(); Container cp = getContentPane(); FlowLayout flow = new FlowLayout(); cp.setLayout(flow); super.setResizable(false); setSize(200, 200); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); menuBar=new JMenuBar(); fileMenu=new JMenu("Αρχειο"); fileOpen=new JMenuItem("Άνοιγμα"); fileOpen.addActionListener(mhandler); fileMenu.add(fileOpen); fileSave=new JMenuItem("Αποθηκευση"); fileSave.addActionListener(mhandler); fileMenu.add(fileSave); fileCopy=new JMenuItem("Αντιγραφή"); fileCopy.addActionListener(mhandler); fileMenu.add(fileCopy); menuBar.add(fileMenu); combo1 = new JComboBox(eidos); combo2 = new JComboBox(posotita); setJMenuBar(menuBar); cp.add(Eidos); cp.add(Posotita); cp.add(text1); cp.add(text2); cp.add(combo1); cp.add(combo2); setContentPane(cp); setVisible(true); } public static void main(String[] arguments) { SuperM app=new SuperM(); app.setVisible(true); } class MenuItemHandler implements ActionListener { public void actionPerformed(ActionEvent e){ if (e.getSource()==fileCopy) { combo1.addItem(makeObj("Item 1")); } else if (e.getSource()==fileSave) { int result=chooser.showSaveDialog(null); String s=chooser.getSelectedFile().getPath(); JOptionPane.showMessageDialog(null, "Choose:" + s,"Results",JOptionPane.INFORMATION_MESSAGE); try{ file=new File(s); output=new FileWriter(file); output.close(); } catch(Exception exc) { System.out.println("ERROR"); } String cmd=e.getActionCommand(); text1.setText(cmd); } } private Object makeObj(String string) { throw new UnsupportedOperationException("Not yet implemented"); } } }
Προτεινόμενες αναρτήσεις
Αρχειοθετημένο
Αυτό το θέμα έχει αρχειοθετηθεί και είναι κλειστό για περαιτέρω απαντήσεις.