import javax.swing.*; import java.awt.event.*; public class Problema1 extends JFrame implements ActionListener{ private private private private JTextField txt1,txt2,txt3; ButtonGroup bg1; JRadioButton radio1,radio2; JButton boton1; public Problema1() { setLayout(null); txt1=new JTextField(); txt1.setBounds(10,10,100,30); add(txt1); txt2=new JTextField(); txt2.setBounds(10,60,100,30); add(txt2); txt3=new JTextField(); txt3.setBounds(10,110,100,30); add(txt3); bg1=new ButtonGroup(); radio1=new JRadioButton("Suma"); radio1.setBounds(150,10,100,30); bg1.add(radio1); add(radio1); radio2=new JRadioButton("Resta"); radio2.setBounds(150,50,100,30); bg1.add(radio2); add(radio2); boton1=new JButton("Aceptar"); boton1.setBounds(150,180,100,30); boton1.addActionListener(this); add(boton1); } public void actionPerformed(ActionEvent e) { if (e.getSource()==boton1) { int valor1=Integer.parseInt(txt1.getText()); int valor2=Integer.parseInt(txt2.getText()); int total=0; if (radio1.isSelected()) { total=valor1+valor2; } if (radio2.isSelected()) { total=valor1-valor2; } String cadena=String.valueOf( total) ; txt3.setText(cadena); // setTitle(Cadena); } } public static void main(String[] ar) { Problema1 formulario1=new Problema1(); formulario1.setBounds(0,0,350,250); formulario1.setVisible(true); } } import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Problema2 extends JFrame implements ActionListener{ private JTextField textfield1; private JTextArea textarea1; public JButton verTabla,salir; public Problema2() { setLayout(null); textfield1=new JTextField(); textfield1.setBounds(10,10,200,30); add(textfield1); textarea1=new JTextArea(); textarea1.setBounds(10,50,300,300); add(textarea1); verTabla = new JButton("Ver tabla"); verTabla.setBounds(350,50,100,30); verTabla.addActionListener(this); add(verTabla); salir = new JButton("Salir"); salir.setBounds(350,100,100,30); salir.addActionListener(this); add(salir); } public void actionPerformed(ActionEvent e) { textarea1.setText(null); if (e.getSource()==salir) { System.exit(0); } if (e.getSource()==verTabla) { int resultado; String linea; String factor2Cadena= textfield1.getText(); int factor2=Integer.parseInt(factor2Cadena); for(int factor1=1;factor1<=10;factor1++){ resultado = factor1*factor2; linea = factor2Cadena +" x "+String.valueOf(factor1)+ " = "+String.valueOf(resultado)+ "\n"; textarea1.setText( textarea1.getText() + linea); // conceptualmente es una concatenacion // textarea1=textarea1+linea //textarea1.append( linea ); //alternativa } textfield1.setText(null); } } public static void main(String[] ar) { Problema2 formulario1=new Problema2(); formulario1.setBounds(0,0,540,400); formulario1.setVisible(true); } }