import java.awt.*;
import javax.swing.*;
public class GraphApp extends JFrame implements ActionListener {
JTextField valor1, valor2, result;
JButton some, subt;
static int val1, val2, resul;
class Fecha extends WindowAdapter {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}
public GraphApp() {
setTitle("GraphApp");
Container c = getContentPane();
c.setLayout(new FlowLayout());
JLabel info = new JLabel("Informe dois número".);
c.add(info);
valor1 = new JTextField(10);
c.add(valor1);
valor2 = new JTextField(10);
c.add(valor2);
some = new JButton("Somar");
c.add(some);
subt = new JButton("Subtrair");
c.add(subt);
JLabel resulta = new JLabel("Resultado:");
c.add(resulta);
result = new JTextField(10);
result.setEditable(false);
c.add(result);
some.addActionListener(this);
subt.addActionListener(this);
this.addActionListener(new Fecha());
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == some) {
val1 = Integer.parseInt(valor1.getText());
val2 = Integer.parseInt(valor2.getText());
fsome(val1, val2);
} else if (e.getSource() == subt) {
val1 = Integer.parseInt(valor1.getText());
val2 = Integer.parseInt(valor2.getText());
fsubt(val1, val2);
}
}
public void fsome(int x, int y) {
resul = x + y;
result.setText(Integer.toString(resul));
}
public void fsubt(int x, int y) {
resul = x - y;
result.setText(Integer.toString(resul));
}
public static void main(String a[]) {
GraphApp a = new GraphApp();
a.show();
}
}
O compilador está apontando erro na linha 20, dois erros. O primeiro: Identificador esperado e o outro: ")" esperado. Só que eu realmente não vejo sentido em encaixar isso na linha 20.
Pergunta
rodfraga
Galera, aí está o código da minha aplicação:
import java.awt.*; import javax.swing.*; public class GraphApp extends JFrame implements ActionListener { JTextField valor1, valor2, result; JButton some, subt; static int val1, val2, resul; class Fecha extends WindowAdapter { public void windowClosing(WindowEvent e) { System.exit(0); } } public GraphApp() { setTitle("GraphApp"); Container c = getContentPane(); c.setLayout(new FlowLayout()); JLabel info = new JLabel("Informe dois número".); c.add(info); valor1 = new JTextField(10); c.add(valor1); valor2 = new JTextField(10); c.add(valor2); some = new JButton("Somar"); c.add(some); subt = new JButton("Subtrair"); c.add(subt); JLabel resulta = new JLabel("Resultado:"); c.add(resulta); result = new JTextField(10); result.setEditable(false); c.add(result); some.addActionListener(this); subt.addActionListener(this); this.addActionListener(new Fecha()); } public void actionPerformed(ActionEvent e) { if (e.getSource() == some) { val1 = Integer.parseInt(valor1.getText()); val2 = Integer.parseInt(valor2.getText()); fsome(val1, val2); } else if (e.getSource() == subt) { val1 = Integer.parseInt(valor1.getText()); val2 = Integer.parseInt(valor2.getText()); fsubt(val1, val2); } } public void fsome(int x, int y) { resul = x + y; result.setText(Integer.toString(resul)); } public void fsubt(int x, int y) { resul = x - y; result.setText(Integer.toString(resul)); } public static void main(String a[]) { GraphApp a = new GraphApp(); a.show(); } }O compilador está apontando erro na linha 20, dois erros. O primeiro: Identificador esperado e o outro: ")" esperado. Só que eu realmente não vejo sentido em encaixar isso na linha 20.
alguém pode me ajudar?
Obrigado
Rodrigo
Link para o comentário
Compartilhar em outros sites
2 respostass a esta questão
Posts Recomendados
Participe da discussão
Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.