I am trying to write a program that converts Hexadecimal to Binary to Decimal, and can convert up to a 5 digit hexadecimal number. The conversions are a whole different matter right now I'm stuck on organizing the GUI. The criteria for the interface is that it must have: One window (a textbox) for inputting the Hex number, one window which outputs the decimal equivalent, and 5 windows arranged in a row for outputting the binary number. The binary equivalents of each Hexadecimal digit must be arranged in an array, the hexadecimal numbers may be the second dimension of the array, and the decimal numbers must be calculated using "the usual algorithm". I have looked at examples and tutorials and what I have come up with is based around a Fahrenheit to Celsius converter. The code I have so far is:
package finalConverter;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Converter extends JFrame {
private JTextField textField;
private JButton convert;
private JLabel hexadecimal, binary, decimal;
public Converter() {
setTitle("Converter");
setSize(400,400);
setLocationRelativeTo(null);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
getContentPane().add(new ConverterPanel());
}
protected class ConverterPanel extends JPanel{
public ConverterPanel(){
setLayout(new GridLayout(3,5));
textField = new JTextField();
convert = new JButton ("Convert");
hexadecimal = new JLabel("Hexadecimal");
binary = new JLabel ("Binary");
decimal = new JLabel ("Decimal");
add(hexadecimal);
add(textField);
add(convert);
add(binary);
add(decimal);
}
}
protected class EventHandler implements ActionListener{
public void actionPerformed(ActionEvent ev){
if(ev.getSource() == convert){
double result = ()
}
}
}
public static void main(String[] args) {
new Converter().setVisible(true);
}
}
When I run this it gives me a window that has two columns and three rows. That is not what I was going for, and tinkering with the numbers in newGridLayout doesn't seem to change anything. Is there some different layout I should be using to get the results I want? Or is it because I am missing textfields and the areas where it outputs the binary numbers? I tried using pack(); in the converter window: It just returned a smaller two column by three row GUI.