jimoaks 0 Newbie Poster

Hello, I am having some trouble writing this java GUI. First in the win1, i cannot get the start and exit button to the bottom of the page along with the jlabel into the center. Next for win2 i cannot resize the "go here" button at the bottom of the page. also from win2 i cant get he add button to update the contents of the jlist, ie click add, write in servers name, and have it appear on the list. the code i have comment out in win2 is what i thought i needed, but I cannot get it too work.

thanks

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;


public class at3 {

    public static void main(String arg[]){

        JFrame frame = new JFrame("Islamorado Fish Company");
        frame.add(new Win1());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();   // Makes size according to panel's preference
        frame.setVisible(true);
   }


}



import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;



public class Win1 extends JPanel {


    private JButton   startButton;
    private JButton   exitButton;
    private Image     background;

    public JButton getStartButton() { return startButton; }
    public JButton getExitButton() { return exitButton; }

    public Win1() {


        GridBagLayout layout = new GridBagLayout();
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.insets = new Insets(10,10,10,10);

        background = Toolkit.getDefaultToolkit().getImage("island.jpg");

        JPanel p1 = new JPanel(new GridBagLayout());
        JPanel p2 = new JPanel(new BorderLayout());

        JButton start = new JButton("Start");
        JButton exit = new JButton("Exit");

        JLabel greet = new JLabel("Welcome to Islamorado Fish Company");



        start.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {

        {


            Win2 Win2Frame = new Win2();
            Win2Frame.setVisible(true);

        }

            }});

            exit.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent e){
                    System.exit(0);
                        }
            });



        gbc.gridx=0;
        gbc.gridy=0;
        p1.add(start, gbc);
        gbc.gridx=1;
        gbc.gridy=0;
        p1.add(exit, gbc);

        p2.add(greet);


        add(p1, BorderLayout.SOUTH);
        add(p2, BorderLayout.CENTER);


        while ((background.getWidth(null) == -1) && (background.getHeight(null) == -1));
        setPreferredSize(new Dimension(background.getWidth(null), background.getHeight(null)));


    }
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.drawImage(background, 0, 0, null);
    }


}



import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;


public class Win2 extends JFrame implements  ActionListener
{

    private JRadioButton m, t, w, r, f, st, sn;
    private ButtonGroup days;
    private JList     serverList;
    private JButton addButton;
    private boolean       inAddMode;
    private Vector      servers;
    private ActionListener      theAddButtonListener;
    private Win2     view;
    private serverlist              selectedServer;


     public JButton getAddButton() { return addButton; }
     public JList getserverList() { return serverList; }





    public Win2()
    {

        servers = new Vector();
        selectedServer = null;

        GridBagLayout layout = new GridBagLayout();
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.insets = new Insets(10,10,10,10);



        JPanel p3 = new JPanel(new BorderLayout());
        JPanel p4 = new JPanel(new GridBagLayout());
        JPanel p5 = new JPanel(new GridBagLayout());
        JButton go = new JButton("Go Here");
        JRadioButton m = new JRadioButton("Monday");
        JRadioButton t = new JRadioButton("Tuesday");
        JRadioButton w = new JRadioButton("Wednesday");
        JRadioButton r = new JRadioButton("Thursday");
        JRadioButton f = new JRadioButton("Friday");
        JRadioButton st = new JRadioButton("Saturday");
        JRadioButton sn= new JRadioButton("Sunday");




        serverList = new JList();
        serverList.setPrototypeCellValue("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
        JScrollPane scrollPane = new JScrollPane( serverList,
        ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
        ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        add(scrollPane);

        addButton = new JButton("Add");


        JLabel label = new JLabel("Please select the day of the week");



        days = new ButtonGroup();

        days.add(m);
        days.add(t);
        days.add(w);
        days.add(r);
        days.add(f);
        days.add(st);
        days.add(sn);

        /*open.addActionListener(this);
        add(open);
        setVisible(true);*/

        p3.add(go);

        gbc.gridx=0;
        gbc.gridy=0;
        p4.add(label, gbc);
        gbc.gridx=0;
        gbc.gridy=1;
        p4.add(m, gbc);
        gbc.gridx=0;
        gbc.gridy=2;
        p4.add(t,gbc);
        gbc.gridx=0;
        gbc.gridy=3;
        p4.add(w,gbc);
        gbc.gridx=0;
        gbc.gridy=4;
        p4.add(r,gbc);
        gbc.gridx=0;
        gbc.gridy=5;
        p4.add(f,gbc);
        gbc.gridx=0;
        gbc.gridy=6;
        p4.add(st,gbc);
        gbc.gridx=0;
        gbc.gridy=7;
        p4.add(sn,gbc);


        gbc.gridx=0;
        gbc.gridy=0;
        p5.add(addButton, gbc);
        gbc.gridx=0;
        gbc.gridy=1;
        p5.add(serverList, gbc);


          theAddButtonListener = new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                addServer();
            }};





        add(p3, BorderLayout.SOUTH);
        add(p4, BorderLayout.WEST);
        add(p5, BorderLayout.EAST);
        setSize(800,600);

        //update();






    }

    public void actionPerformed(ActionEvent event)
    {
    //  new Win2();


        JFrame frame2 = new JFrame("Daily Set up");
        frame2.add(new Win2());
        frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame2.pack();  // Makes size according to panel's preference
        frame2.setVisible(true);

}


    private void enableListeners() {
        view.getAddButton().addActionListener(theAddButtonListener);
    }


     private void disableListeners() {
        view.getAddButton().removeActionListener(theAddButtonListener);
     }


     private void selectServer() {
        selectedServer = (serverlist)(view.getserverList().getSelectedValue());
        //update();
    }


     private void addServer() {
        inAddMode = true;

        serverlist  aServer = new serverlist();

        servers.add(aServer);

        // Now bring up the dialog box
       // BuddyDetailsDialog dialog = new BuddyDetailsDialog(this, "Buddy Details Dialog", true, aBuddy);
       // dialog.setVisible(true);
    }

    private void updateList() {
         boolean  foundSelected = false;

        if (selectedServer != null)
            view.getserverList().setSelectedValue(selectedServer, true);
    }


    /*  private void update() {
        disableListeners();
       // updateList();
        //updateRemove();
        enableListeners();
        }*/


}




/**
 * @(#)serverlist.java
 *
 *
 * @author
 * @version 1.00 2012/5/3
 */


public class serverlist {
    private String   name;

    public serverlist() {

        name = "";
    }
    public serverlist(String aName) {
        name = aName;

    }
        public String getName() { return name; }

        public void setName(String newName) { name = newName; }


        public String toString() {
        return(name);
    }


}