Autor Tema: Java ejemplo JPanel, JTextField, JRadioButton elegir opciones usuarios  (Leído 3755 veces)

josephb401

  • Visitante
el programa no me da error pero cuando trato de ejecutarlo no funciona queria saber si alquien me pudiera ayudar se lo agradeseria bastante

Código: [Seleccionar]
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.*;

public class test extends JFrame
{

private JPanel panelTitle;
private JPanel statictisPanel;

private TitledBorder borderTitle;
private TitledBorder statisticsTitle;

private JTextField text1;
private JTextField text2;
private JTextField text3;
private JTextField text4;
private JTextField text5;

private JRadioButton avrgAllTest;
private JRadioButton avrgLess1;
private JRadioButton avrgLess2;
private ButtonGroup avrgGroup;



public test()
{

testScorePanel();
buildStatisticsPanel();

// set title
setTitle("Jose A. Pimentel");

add(panelTitle, BorderLayout.NORTH);
add(statictisPanel, BorderLayout.CENTER);


pack();

// specify what happens when the close button is clicked
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

// Display the windows
setVisible(true);

}


public void testScorePanel()
{
panelTitle = new JPanel();

panelTitle.setLayout(new GridLayout( 1, 5) );
borderTitle.setBounds(46, 16, 150, 50);


borderTitle = new TitledBorder("Test Scores");

text1 = new JTextField(4);
text2 = new JTextField(4);
text3 = new JTextField(4);
text4 = new JTextField(4);
text5 = new JTextField(4);

panelTitle.setBorder(borderTitle);

panelTitle.add(text1);
panelTitle.add(text2);
panelTitle.add(text3);
panelTitle.add(text4);
panelTitle.add(text5);

}

public void buildStatisticsPanel()
{

statictisPanel = new JPanel();

statictisPanel.setLayout(new GridLayout( 4, 1) );
statictisPanel.setBounds(46, 76, 150, 50);

statisticsTitle = new TitledBorder("Statistics");


avrgAllTest = new JRadioButton("Average Includes All Tests", true);
avrgLess1 = new JRadioButton("Average Drops Lowest Test");
avrgLess1 = new JRadioButton("Average Drops 2 Lowest Tests");

statictisPanel.setBorder(statisticsTitle);

avrgGroup = new ButtonGroup();
avrgGroup.add(avrgAllTest);
avrgGroup.add(avrgLess1);
avrgGroup.add(avrgLess2);

//statictisPanel.setBorder(BorderFactory.createTitledBorder("Bagel"));

statictisPanel.add(avrgAllTest);
statictisPanel.add(avrgLess1);
statictisPanel.add(avrgLess2);



}

}


Código: [Seleccionar]
public class Program7
{


public static void main(String[] args)
{

test application = new test();


}



}
« Última modificación: 01 de Mayo 2015, 21:47 por César Krall »

César Krall

  • Moderador Global
  • Experto
  • *******
  • Mensajes: 2078
  • No vales por lo que dices, sino por lo que haces
    • Ver Perfil
    • aprenderaprogramar.com
Re:GUI aplicacion JAVA
« Respuesta #1 en: 01 de Mayo 2015, 08:01 »
Hola, a mí sí me da error en esta línea:

borderTitle.setBounds(46, 16, 150, 50);

El error que marca es cannot find symbol - method setBounds(int, int, int, int)

Si intentas compilarlo a tí también te debe saltar el error, a no ser que estés probando otro código distinto.

Saludos!
Responsable de departamento de producción aprenderaprogramar.com

josephb401

  • Visitante
Re:GUI aplicacion JAVA
« Respuesta #2 en: 01 de Mayo 2015, 18:34 »
sabes una forma de solucionar ese problema?

César Krall

  • Moderador Global
  • Experto
  • *******
  • Mensajes: 2078
  • No vales por lo que dices, sino por lo que haces
    • Ver Perfil
    • aprenderaprogramar.com
Re:GUI aplicacion JAVA
« Respuesta #3 en: 01 de Mayo 2015, 21:46 »
Con pequeños cambios se logra que compile pero te recomiendo que aprendas java siguiendo el curso http://aprenderaprogramar.com/index.php?option=com_content&view=category&id=68&Itemid=188

El código que compila es

Código: [Seleccionar]
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.*;

public class test extends JFrame {

    private JPanel panelTitle;
    private JPanel statictisPanel;

    private TitledBorder borderTitle;
    private TitledBorder statisticsTitle;

    private JTextField text1;
    private JTextField text2;
    private JTextField text3;
    private JTextField text4;
    private JTextField text5;

    private JRadioButton avrgAllTest;
    private JRadioButton avrgLess1;
    private JRadioButton avrgLess2;
    private ButtonGroup avrgGroup;


    public test() {

        testScorePanel();
        buildStatisticsPanel();

        // set title
        setTitle("Jose A. Pimentel");

        add(panelTitle, BorderLayout.NORTH);
        add(statictisPanel, BorderLayout.CENTER);

        pack();
        // specify what happens when the close button is clicked
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        // Display the windows
        setVisible(true);

    }

    public void testScorePanel()
    {
        panelTitle = new JPanel();

        panelTitle.setLayout(new GridLayout( 1, 5) );

        borderTitle = new TitledBorder("Test Scores");
        //borderTitle.setBounds(46, 16, 150, 50);


        text1 = new JTextField(4);
        text2 = new JTextField(4);
        text3 = new JTextField(4);
        text4 = new JTextField(4);
        text5 = new JTextField(4);

        panelTitle.setBorder(borderTitle);

        panelTitle.add(text1);
        panelTitle.add(text2);
        panelTitle.add(text3);
        panelTitle.add(text4);
        panelTitle.add(text5);

    }

    public void buildStatisticsPanel()
    {

        statictisPanel = new JPanel();

        statictisPanel.setLayout(new GridLayout( 4, 1) );
        statictisPanel.setBounds(46, 76, 150, 50);

        statisticsTitle = new TitledBorder("Statistics");

        avrgAllTest = new JRadioButton("Average Includes All Tests", true);
        avrgLess1 = new JRadioButton("Average Drops Lowest Test");
        avrgLess2 = new JRadioButton("Average Drops 2 Lowest Tests");

        statictisPanel.setBorder(statisticsTitle);

        avrgGroup = new ButtonGroup();
        avrgGroup.add(avrgAllTest);
        avrgGroup.add(avrgLess1);
        avrgGroup.add(avrgLess2);

        //statictisPanel.setBorder(BorderFactory.createTitledBorder("Bagel"));

        statictisPanel.add(avrgAllTest);
        statictisPanel.add(avrgLess1);
        statictisPanel.add(avrgLess2);
    }

}


Clase con el main

Código: [Seleccionar]
public class Program7{

    public static void main(String[] args) {
        test application = new test();
    }
}
Responsable de departamento de producción aprenderaprogramar.com

 

Sobre la educación, sólo puedo decir que es el tema más importante en el que nosotros, como pueblo, debemos involucrarnos.

Abraham Lincoln (1808-1865) Presidente estadounidense.

aprenderaprogramar.com: Desde 2006 comprometidos con la didáctica y divulgación de la programación

Preguntas y respuestas

¿Cómo establecer o cambiar la imagen asociada (avatar) de usuario?
  1. Inicia sesión con tu nombre de usuario y contraseña.
  2. Pulsa en perfil --> perfil del foro
  3. Elige la imagen personalizada que quieras usar. Puedes escogerla de una galería de imágenes o subirla desde tu ordenador.
  4. En la parte final de la página pulsa el botón "cambiar perfil".