• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Help with Java GUI Programming

Status
Not open for further replies.

Revoh

Member
Hey Gaffers, I'm new at Java/programming, please help me with this. I've read a bunch of tutorials but still can't quite grasp this.

One of the exercises I'm having problem with is this:
HL7Ef.jpg

I have to recreate that window, it doesn't need any functionality, just to be exactly as that image.

I ended up with this:
F8qjz.png

As you can see, all buttons and text are there I just don't know how to align them
Code:
Code:
import javax.swing.*;

public class Tema2 {
	public static void main(String[] args) {
		
		JFrame ventana = new JFrame("Prueba");
		JPanel panel = new JPanel();
		
		JLabel etiqueta = new JLabel("Segundo Parcial", JLabel.CENTER);
		JTextField campo = new JTextField("", 25);
		JButton ok = new JButton("Botón simple");
		
		JCheckBox checkbox1 = new JCheckBox("Negrita");
		JCheckBox checkbox2 = new JCheckBox("Cursiva");
		
		JRadioButton radio1 = new  JRadioButton("Simple");
		JRadioButton radio2 = new  JRadioButton("Negrita");
		
	
		panel.add(radio1);
		panel.add(radio2);
		panel.add(ok);
		panel.add(etiqueta);
		panel.add(checkbox1);
		panel.add(checkbox2);
		panel.add(campo);
		
		ventana.setSize(300, 200);
		ventana.setContentPane(panel);
		ventana.setVisible(true);
	}
}

Same with this:
CEsDs.jpg


Ended up with this:
UQlmQ.png


I don't know how to do the menu thing at the top of the window, that drop-down list and that box where it says Observaciones and you can write stuff.

And here's the code:
Code:
import javax.swing.*;

public class Tema3 {
	public static void main(String[] args) {
		JFrame ventana = new JFrame("Trabajo nro 2");
		JPanel panel = new JPanel();
		JLabel etiqueta = new JLabel("Nombre del Alumno:");
		JCheckBox java = new JCheckBox("Introducción a Java");
		JCheckBox javaAvanzado = new JCheckBox("Java Avanzado");
		JTextField campo = new JTextField("Escribe aquí");
		
		panel.add(etiqueta);
		panel.add(java);
		panel.add(javaAvanzado);
		panel.add(campo);
		
		ventana.setSize(400, 250);
		ventana.setContentPane(panel);
		ventana.setVisible(true);
	}
}

Any help would be greatly appreciated!
 

AngryMoth

Member
Status
Not open for further replies.
Top Bottom