hey guys, i was wondering if anyone could help, basicly at the moment (for the last few hours) iv been tring to find a way to align an container, to enable me to have my current work on one side (left or right) and a JTextArea on the other.
the project is a java address book, which needs to be able to do all the usual things such as edit and add ect. However it also needs to display read in data within the text area.
Any help would be greatly appreciated.
(btw this code is nowhere near finished, just seting up the GUI atm.)
import java.util.*;
import java.io.*;
import javax.swing.*;
import java.text.*;
public class Q3 implements ActionListener
{
JFrame addressBook;
JPanel panel1;
JLabel labName, labAddress, labPhone,labMob;
JTextField textName, textAddress, textPhone, textMob;
JButton buttonSave, buttonDelete, buttonImport, buttonSearch, buttonForward, buttonBack, buttonExit;
JTextArea text_area;
String name, address;
int phone, mob;
int recordNumber; // used to naviagate using >> and << buttons
Container container1;
public static void main(String args[])
{
new Q3();
}
public Q3()
{
name = "";
address = "";
phone = -1 ; //Stores 0 to indicate no Phone Number
mob = -1;
recordNumber = -1;
createGUI();
}
public void createGUI()
{
/*Create a frame, get its contentpane and set layout*/
addressBook = new JFrame("Address Book");
container1 = addressBook.getContentPane();
container1.setLayout(new GridBagLayout());
container1.setBackground(Color.black);
container1.setSize(300, 300);
//Arrange components on contentPane and set Action Listeners to each JButton
arrangeComponents();
addressBook.setSize(600,300);
addressBook.setResizable(false);
addressBook.setVisible(true);
}
public void arrangeComponents()
{
text_area = new JTextArea();
labName = new JLabel("Name");
labName.setForeground(Color.white);
labAddress = new JLabel("Address");
labAddress.setForeground(Color.white);
labPhone = new JLabel("Home Number");
labPhone.setForeground(Color.white);
labMob = new JLabel("Mobile Number");
labMob.setForeground(Color.white);
textName = new JTextField(20);
textAddress = new JTextField(20);
textPhone = new JTextField(20);
textMob = new JTextField(20);
buttonSave = new JButton("Save");
buttonDelete = new JButton("Delete");
buttonSearch = new JButton("Search");
buttonImport = new JButton("Import");
buttonForward = new JButton("FORWARD");
buttonBack = new JButton("BACK");
buttonExit = new JButton("Exit");
/*add all initialized components to the container*/
GridBagConstraints gridBagConstraintsx17 = new GridBagConstraints();
gridBagConstraintsx17.gridx = 5;
gridBagConstraintsx17.gridy = 6;
gridBagConstraintsx17.insets = new Insets(5,5,5,5);
container1.add(text_area, gridBagConstraintsx17);
GridBagConstraints gridBagConstraintsx01 = new GridBagConstraints();
gridBagConstraintsx01.gridx = 0;
gridBagConstraintsx01.gridy = 0;
gridBagConstraintsx01.insets = new Insets(5,5,5,5);
container1.add(labName, gridBagConstraintsx01);
GridBagConstraints gridBagConstraintsx02 = new GridBagConstraints();
gridBagConstraintsx02.gridx = 1;
gridBagConstraintsx02.insets = new Insets(5,5,5,5);
gridBagConstraintsx02.gridy = 0;
gridBagConstraintsx02.gridwidth = 2;
gridBagConstraintsx02.fill = GridBagConstraints.BOTH;
container1.add(textName, gridBagConstraintsx02);
GridBagConstraints gridBagConstraintsx03 = new GridBagConstraints();
gridBagConstraintsx03.gridx = 0;
gridBagConstraintsx03.insets = new Insets(5,5,5,5);
gridBagConstraintsx03.gridy = 1;
container1.add(labAddress, gridBagConstraintsx03);
GridBagConstraints gridBagConstraintsx04 = new GridBagConstraints();
gridBagConstraintsx04.gridx = 1;
gridBagConstraintsx04.insets = new Insets(5,5,5,5);
gridBagConstraintsx04.gridy = 1;
gridBagConstraintsx04.gridwidth = 2;
gridBagConstraintsx04.fill = GridBagConstraints.BOTH;
container1.add(textAddress, gridBagConstraintsx04);
GridBagConstraints gridBagConstraintsx05 = new GridBagConstraints();
gridBagConstraintsx05.gridx = 0;
gridBagConstraintsx05.insets = new Insets(5,5,5,5);
gridBagConstraintsx05.gridy = 2;
container1.add(labPhone, gridBagConstraintsx05);
GridBagConstraints gridBagConstraintsx06 = new GridBagConstraints();
gridBagConstraintsx06.gridx = 1;
gridBagConstraintsx06.gridy = 2;
gridBagConstraintsx06.insets = new Insets(5,5,5,5);
gridBagConstraintsx06.gridwidth = 2;
gridBagConstraintsx06.fill = GridBagConstraints.BOTH;
container1.add(textPhone, gridBagConstraintsx06);
GridBagConstraints gridBagConstraintsx07 = new GridBagConstraints();
gridBagConstraintsx07.gridx = 0;
gridBagConstraintsx07.insets = new Insets(5,5,5,5);
gridBagConstraintsx07.gridy = 3;
container1.add(labMob, gridBagConstraintsx07);
GridBagConstraints gridBagConstraintsx08 = new GridBagConstraints();
gridBagConstraintsx08.gridx = 1;
gridBagConstraintsx08.gridy = 3;
gridBagConstraintsx08.gridwidth = 2;
gridBagConstraintsx08.insets = new Insets(5,5,5,5);
gridBagConstraintsx08.fill = GridBagConstraints.BOTH;
container1.add(textMob, gridBagConstraintsx08);
GridBagConstraints gridBagConstraintsx09 = new GridBagConstraints();
gridBagConstraintsx09.gridx = 0;
gridBagConstraintsx09.gridy = 4;
gridBagConstraintsx09.insets = new Insets(5,5,5,5);
container1.add(buttonSave, gridBagConstraintsx09);
GridBagConstraints gridBagConstraintsx10 = new GridBagConstraints();
gridBagConstraintsx10.gridx = 1;
gridBagConstraintsx10.gridy = 4;
gridBagConstraintsx10.insets = new Insets(5,5,5,5);
container1.add(buttonDelete, gridBagConstraintsx10);
GridBagConstraints gridBagConstraintsx11 = new GridBagConstraints();
gridBagConstraintsx11.gridx = 2;
gridBagConstraintsx11.gridy = 4;
gridBagConstraintsx11.insets = new Insets(5,5,5,5);
container1.add(buttonImport, gridBagConstraintsx11);
GridBagConstraints gridBagConstraintsx12 = new GridBagConstraints();
gridBagConstraintsx12.gridx = 0;
gridBagConstraintsx12.gridy = 5;
gridBagConstraintsx12.insets = new Insets(5,5,5,5);
container1.add(buttonBack, gridBagConstraintsx12);
GridBagConstraints gridBagConstraintsx13 = new GridBagConstraints();
gridBagConstraintsx13.gridx = 1;
gridBagConstraintsx13.gridy = 5;
gridBagConstraintsx13.insets = new Insets(5,5,5,5);
container1.add(buttonSearch, gridBagConstraintsx13);
GridBagConstraints gridBagConstraintsx14 = new GridBagConstraints();
gridBagConstraintsx14.gridx = 2;
gridBagConstraintsx14.gridy = 5;
gridBagConstraintsx14.insets = new Insets(5,5,5,5);
container1.add(buttonForward, gridBagConstraintsx14);
GridBagConstraints gridBagConstraintsx16 = new GridBagConstraints();
gridBagConstraintsx16.gridx = 1;
gridBagConstraintsx16.gridy = 6;
gridBagConstraintsx16.insets = new Insets(5,5,5,5);
container1.add(buttonExit, gridBagConstraintsx16);
buttonExit.addActionListener(this);
}
public void actionPerformed (ActionEvent e)
{
if (e.getSource() == buttonExit)
{
System.exit(0);
}
}
}