2
I am in need of help in the following, I have a window that the user can activate the Jcheckboxes to write in the Jtextarea that is below, as the following image:

What I wanted is that when you pressed the Jcheckbox of the Keyboard appeared a message saying "the keyboard is damaged" and if I removed the check of Jcheckbox not appear anything below, as for example:

What I’ve been able to do is get Jcheckbox to write what I want, I just wanted to say that Jcheckbox s are not the only thing that I have in the program,I mean, in addition to this Jtextarea being shown the content of the Jcheckbox s actions is shown some notes that will be made in the next frame,
1-"the keyboard is damaged"
2-"the rat is damaged"
3-"the monitor is damaged"
4-"the tower is damaged"5 and another for the details
All this is written to store in a document . txt.
private JPanel contentPane;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
try {
Aluno7_Ruben frame = new Aluno7_Ruben();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Aluno7_Ruben() {
setIconImage(Toolkit.getDefaultToolkit().getImage("C:\\Users\\Jo\u00E3o Gil\\workspace\\sala de aula\\pic\\icon\\Science-Classroom-icon.png"));
setTitle("PC7-Ruben Gato");
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblNewLabel = new JLabel("Detalhes/Notas:");
lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 17));
lblNewLabel.setBounds(10, 106, 194, 23);
contentPane.add(lblNewLabel);
JLabel lblNewLabel_1 = new JLabel("Localiza\u00E7\u00E3o da avaria:");
lblNewLabel_1.setFont(new Font("Tahoma", Font.PLAIN, 17));
lblNewLabel_1.setBounds(10, 11, 169, 20);
contentPane.add(lblNewLabel_1);
JCheckBox Teclado = new JCheckBox ("Teclado");
Teclado.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
PrintWriter writer;
try {
String texto1="O teclado esta danificado";
writer = new PrintWriter("C:\\Users\\João Gil\\workspace\\sala de aula\\pic\\notas.txt");
writer.println(texto1 );
writer.close();
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
Teclado.setToolTipText("Selecionar caso esteja danificado");
Teclado.setBounds(6, 54, 94, 23);
contentPane.add(Teclado);
JCheckBox Rato = new JCheckBox ("Rato");
Rato.setToolTipText("Selecionar caso esteja danificado");
Rato.setBounds(98, 54, 81, 23);
contentPane.add(Rato);
JCheckBox Monitor = new JCheckBox ("Monitor");
Monitor.setToolTipText("Selecionar caso esteja danificado");
Monitor.setBounds(190, 54, 96, 23);
contentPane.add(Monitor);
JCheckBox Torre = new JCheckBox ("Torre");
Torre.setToolTipText("Selecionar caso esteja danificado");
Torre.setBounds(288, 54, 109, 23);
contentPane.add(Torre);
JButton Adicionar_notas = new JButton("Escrever novas notas");
Adicionar_notas.addActionListener(new ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
FAZJA(evt);
}
});
Adicionar_notas.setBounds(137, 224, 159, 23);
contentPane.add(Adicionar_notas);
File file = new File("C:\\Users\\João Gil\\workspace\\sala de aula\\pic\\notas.txt");
FileInputStream fis = null;
String texto = "";
try {
fis = new FileInputStream(file);
int content;
while ((content = fis.read()) != -1) {
texto += (char) content;
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (fis != null) {
fis.close();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
JTextArea textArea1 = new JTextArea(texto);
textArea1.setEditable(false);
textArea1.setWrapStyleWord(true);
textArea1.setBounds(10, 128, 414, 85);
contentPane.add(textArea1);
}
protected void FAZJA(ActionEvent evt) {
this.dispose();
new Gravação_Dados().setVisible(true);
}
Here’s the code of this frame. I was doing the Jcheckbox experiments on the keyboard but I couldn’t. I really need help I can’t find anything anywhere.
sorry but apart from editing knows how to solve my problem ?
– MD4tw
John, tried to pass the value of
texto1straight to thetextArea1? Thus:textArea1.append(texto1);?– Gustavo Cinque
If you’re going to do as I said, the best thing would be to instantiate
texto, and all its cargo, and thetextArea1at the beginning of class.– Gustavo Cinque
Not yet tried,I will try, thanks for the suggestion! If you can’t already I have an idea how I will do
– MD4tw
I ended up taking your codes and creating a functional replica here in mine. I would have a few more points to take into account, so I’ll put an answer, @Joao.
– Gustavo Cinque