Vorrei creare un archivio di medicinali su un file.mi dici dove sbaglio?
public Far() {
setIconImage(Toolkit.getDefaultToolkit().getImage("C:\\Users\\xxxxxx\\Desktop\\images.jpg"));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 498, 366);
// jMenu
JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
Nome = new JTextField();
Nome.setBounds(10, 11, 205, 20);
contentPane.add(Nome);
Nome.setColumns(10);
PrincipioAttivo = new JTextField();
PrincipioAttivo.setBounds(10, 57, 205, 20);
contentPane.add(PrincipioAttivo);
PrincipioAttivo.setColumns(10);
JComboBox<String> comboBox = new JComboBox<String>();
comboBox.setBounds(10, 99, 205, 20);
contentPane.add(comboBox);
comboBox.addItem("Seleziona una tipologia");
comboBox.addItem("Compresse");
comboBox.addItem("Sciroppo");
comboBox.addItem("Crema");
comboBox.addItem("Fiale");
comboBox.addItem("Supposte");
comboBox.addItem("Altro");
Scadenza = new JFormattedTextField();
Scadenza.setBounds(10, 150, 86, 20);
contentPane.add(Scadenza);
Scadenza.setColumns(10);
JLabel lblNome = new JLabel("Nome");
lblNome.setBounds(317, 14, 46, 14);
contentPane.add(lblNome);
JLabel lblPrincipioAttivo = new JLabel("Principio Attivo");
lblPrincipioAttivo.setBounds(302, 59, 122, 17);
contentPane.add(lblPrincipioAttivo);
JLabel lblNewLabel_1 = new JLabel("Tipologia");
lblNewLabel_1.setBounds(302, 102, 122, 14);
contentPane.add(lblNewLabel_1);
JLabel lblNewLabel_2 = new JLabel("Scadenza");
lblNewLabel_2.setBounds(317, 153, 78, 14);
contentPane.add(lblNewLabel_2);
JButton btnNewButton = new JButton("Cerca");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
}
});
/*String pa=PrincipioAttivo.getText();
GregorianCalendar sc= scad.getData();*/
JButton btnAggiungi = new JButton("Aggiungi");
btnAggiungi.setBounds(7, 241, 89, 23);
contentPane.add(btnAggiungi);
btnAggiungi.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
Farma farm=new Farma();
farm.getNome();
FileOutputStream w = null;
try {
w=new FileOutputStream("C:\\Users\\xxxxx\\Desktop\\farmaco.txt");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
PrintStream b=new PrintStream(w);
b.println(Nome.getText());
b.close();
}}
/*BufferedWriter b;
b=new BufferedWriter(w);
try {
b.write(Nome.toString());
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
b.write(pa.toString());
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}*/