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.