Click to See Complete Forum and Search --> : Problem with classes
fraker
08-26-2004, 11:28 AM
Hi, I'm developping a simple JAVA Applet and I have a problem
I have a class called LUIweb which is the main class. Here is a part of it.
public class LUIweb extends JApplet implements Runnable {
public void run() {
DisplayMessage("JAVA rocks");
}
public void DisplayMessage(String message){
jtextArea.append(message);
middlePanel.removeAll();
middlePanel.add(textScrollPane, BorderLayout.CENTER);
middlePanel.validate();
middlePanel.repaint();
}
}
It displays the message "JAVA rocks" in my JTextArea. But when another class from the same package calls DisplayMessage, nothing is displayed in my JTextArea
public class Data_net extends LUIweb{
public void Test(){
DisplayMessage("NON");
}
}
Have you got any idea to fix that?
Thank you for you help
mnuttall
08-26-2004, 02:39 PM
Don't see anything readily.
Need more code.
But do try adding an .invalidate(); before the validate.
fraker
08-26-2004, 03:33 PM
I already tried "invalidate()" before validate(), no good result
package applet;
import java.awt.*;
import java.util.Vector;
import java.lang.String;
import javax.swing.*;
import applet.Language;
public class LUIweb extends JApplet implements Runnable {
Vector Soft;
Vector Version;
public JPanel middlePanel = new JPanel();
public JTextArea textArea = new JTextArea();
public JScrollPane textScrollPane = new JScrollPane(textArea,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROL LBAR_AS_NEEDED);
public Container container;
public LUIweb(){
container = getContentPane();
textArea = new JTextArea(30,40);
textArea.setEditable(false);
middlePanel = new JPanel();
//textArea.setPreferredSize(new Dimension(400,450));
textScrollPane = new JScrollPane(textArea,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBA R_ALWAYS);
middlePanel.add(textScrollPane, BorderLayout.CENTER);
container.add(middlePanel, BorderLayout.CENTER);
}
public void init(){
container = getContentPane();
textArea = new JTextArea(30,40);
textArea.setEditable(false);
middlePanel = new JPanel();
//textArea.setPreferredSize(new Dimension(400,450));
textScrollPane = new JScrollPane(textArea,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBA R_ALWAYS);
middlePanel.add(textScrollPane, BorderLayout.CENTER);
container.add(middlePanel, BorderLayout.CENTER);
}
public void start() {
(new Thread(this)).start();
}
// Arr?t de l'applet
public void stop() {
while(true);
}
// Un nouveau thread pour la r?actualisation de l'applet
public void run() {
DisplayMessage(Language.CONNECT_DB);
Data_net Donnee_net=new Data_net();
DisplayMessage("Connecting to "+Donnee_net.GetHost()+" with user "+Donnee_net.GetUser()+"...\n");
Donnee_net.Test();
}
public void ShowWish(Vector Softs, Vector Versions,char Action){
DisplayMessage(Language.WISH+"\n");
for (int i=0;i<Softs.size();i++){
String message=(String) Softs.get(i); message=message.concat((String) Versions.get(i));
String[] t = message.split("\n");
message = t[0];
for (int j=1; j < t.length; j++)
message = message.concat("_".concat(t[j])+"\n");
DisplayMessage("\t"+message);
}
}
public void DisplayMessage(String message){
this.textArea.append(message);
this.middlePanel.removeAll();
this.middlePanel.add(textScrollPane, BorderLayout.CENTER);
// repaint
this.middlePanel.validate();
this.middlePanel.repaint();
}
public void main(String[] arguments) throws NullPointerException {
}
}
package applet;
import com.maverick.ssh.*;
import com.maverick.ssh1.Ssh1Client;
import com.maverick.ssh2.*;
import com.sshtools.net.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Vector;
import javax.swing.*;
public class Data_net extends LUIweb{
public Data_net(){
DisplayMessage("TEST");
AskHost();
AskUser();
}
public void AskHost(){
String inputValue = JOptionPane.showInputDialog(Language.ASKHOST);
hostname=inputValue;
int idx = hostname.indexOf(':');
if(idx > -1) {
port = Integer.parseInt(hostname.substring(idx+1));
hostname = hostname.substring(0, idx);
}
}
public void AskPass(){
Frame frame = new Frame();
while (frame.password==null);
password=new String(frame.password);
}
public String GetPass(){
return password;
}
public String GetHost(){
return hostname;
}
public String GetUser(){
return username;
}
public void AskUser(){
String inputValue = JOptionPane.showInputDialog(Language.ASKUSER);
username = inputValue;
if(username==null || username.trim().equals(""))
username = System.getProperty("user.name");
}
public void Test(){
DisplayMessage("NON");
}
}
So here are two of my classes. Every thing is working but the call of DisplayMessage in Data_net...
I hope it'll help you to find a solution
mnuttall
08-27-2004, 07:59 AM
Ok. Lots of issues. I'll skip those. But it looks like the problem (and the issues hide it) is that you don't call the super class' constructor or the init method.
fraker
08-27-2004, 09:03 AM
Ok, I've fix it thanks to a friend.
in my LUIweb class, I call a method from Data_net with the reference from LUIweb like that:
Donnee_net.Test(this);
what gives in Data_net class:
public void Test(LUIweb instance){
instance.DisplayMessage("NON");
}
Here we go!!
Nevertheless thanks for your help mnuttall.
mnuttall
08-27-2004, 05:51 PM
Glad you got it working.
But you probably shouldn't have as a parameter to a method the class in which the method exists. Again, not seeing all the code makes it difficult. Calling the super's constructor would definitely be better.
devx.com
Copyright Internet.com Inc. All Rights Reserved