Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / September 2005

Tip: Looking for answers? Try searching our database.

Frames

Thread view: 
Caroline B - 11 Sep 2005 21:16 GMT
Can anyone help me please. I'm trying to set up a frame which will have two
buttons and a welcom message. Its the beginnings of a basic client server
login / registration system. For some reason though, one of the buttons I've
added onto the frame seems to expand to the size of the frame itself. The
code is below, any help would be great.

package TMA03Client;

import java.awt.*;
import com.borland.jbcl.layout.*;
import java.io.*;
import java.net.*;
import java.awt.event.*;
import java.util.*;
import java.security.*;
import blowfish.*;

public class Client extends Frame {

   private Frame mainPage = new Frame();
   private Frame registerPage = new Frame();
   private Frame loginPage = new Frame();

   private Label introText = new Label();

   private TextField fullName = new TextField();
   private TextField userAddress = new TextField();
   private TextField userTelephone = new TextField();
   private TextField userLogin = new TextField();
   private TextField userPassword = new TextField();
   private TextField userConfirm = new TextField();
   private TextField userName = new TextField();
   private TextField logPassword = new TextField();

   private Button registerButton = new Button();
   private Button loginButton = new Button();
   private Button sumbitRegister = new Button();
   private Button sumbitLogin = new Button();

   private int totalBuys = 0;

   private Socket s = null;
   private InputStream is = null;
   private OutputStream os = null;
   private PrintWriter pw = null;
   private BufferedReader bf = null;
   private ClientCommandSet cSet = null;
   private ClientResponseSet rSet = null;

   public Client() {
       try {
           jbInit();
           setup();
       } catch (Exception e) {
           e.printStackTrace();
       }
   }

   private void jbInit() throws Exception {
       registerButton.setLabel("Register Details");
       registerButton.addActionListener(new java.awt.event.ActionListener()
{
           public void actionPerformed(ActionEvent e) {
               registerButton_actionPerformed(e);
           }
       });

       loginButton.setLabel("Login");
       loginButton.addActionListener(new java.awt.event.ActionListener() {
           public void actionPerformed(ActionEvent e) {
               loginButton_actionPerformed(e);
           }
       });

       mainPage.g
       introText.setText("Welcome to the OU TMA03 System");
       introText.setSize(100,100);
       introText.setLocation(0,0);
       mainPage.add(registerButton);
       registerButton.setSize(100,100);
       registerButton.setLocation(100,100);
       mainPage.add(loginButton);
       loginButton.setSize(100,100);
       loginButton.setLocation(100,100);
       mainPage.setSize(500,500);
       mainPage.setLocation(100,100);
       mainPage.setVisible(true);
       mainPage.setResizable(true);
       registerPage.setVisible(false);
       loginPage.setVisible(false);
       mainPage.pack();

     
   }

   public void setup() {
       try {
           s = new Socket("127.0.0.1", 3000);
           is = s.getInputStream();
           os = s.getOutputStream();
           pw = new PrintWriter(os, true);

           bf = new BufferedReader
           (new InputStreamReader(is));
           cSet = new ClientCommandSet(pw);
       } catch (Exception e) {
           System.out.println("Trouble contacting the server " + e);
       }
   }

   void loginButton_actionPerformed(ActionEvent e) {

       if (cSet != null) {
           cSet.loginCommand();
       }
       try {

           pw.close();
           bf.close();
           is.close();
           os.close();
           s.close();
       } catch (Exception ex) {};
       System.exit(0);
   }

   void registerButton_actionPerformed(ActionEvent e) {

       if (cSet != null) {
           cSet.registerCommand();
       }
       try {

           pw.close();
           bf.close();
           is.close();
           os.close();
           s.close();
       } catch (Exception ex) {};
       System.exit(0);
   }

   public static void main(String[] args){

       Client cl = new Client();
   }
}
Roedy Green - 12 Sep 2005 04:49 GMT
>        introText.setSize(100,100);
>        introText.setLocation(0,0);
>        mainPage.add(registerButton);
>        registerButton.setSize(100,100);
>        registerButton.setLocation(100,100);

You are coding in C and it is getting you in trouble. In Java you VERY
rarely set the size and location of something with explicit code.  If
you do, you must set the set the layout manager to null,
this.setLayout( null );  which you did not do. The default
layoutmanager is likely overriding your settings.

You need to learn about Layouts that automatically size and position
components for you.

See http://mindprod.com/jgloss/layout.html

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.