using classes in applets

P

Prosper

Hello


can I use classes in applets?

it doesn't return an error but the called class
doesn't do anything...


thx!
 
P

Prosper

Andrew said:
Prosper wrote:
..



IE6 on XP?, Lynx on '95?,
Moz1.4?, Safari? ..your dog?

I'm using Java 1.4.2
Netbeans editor with Applet Viewer for debug

testing under Firebird 0.8 and IE 6 SP1
 
A

Andrew Thompson

Prosper wrote:
(class not found)
....
I'm using Java 1.4.2
Netbeans editor with Applet Viewer for debug

testing under Firebird 0.8 and IE 6 SP1

How about an URL?
http://www.physci.org/codes/sscce.jsp
The applet with a link to the code.

I could spend more time answering
your question and pondering the
information you left out, but instead
I won't..
 
P

Prosper

ok, sorry

here is the (trimmed) code that doesn't work.

I want to see the buttons and labels created in
MenuUI in my applet window (QbusMenu).


// QbusMenu
import java.net.*;
import javax.swing.*;
import java.awt.*;

public class QbusMenu extends JApplet {
MenuUI menuUI;

public void init(){
try {
System.out.println("INIT1");
menuUI = new MenuUI();
this.getContentPane().setLayout( new
BorderLayout() );

this.getContentPane().add(menuUI.getThePanel() );

} catch (Exception e) {
System.out.println(e.getMessage());
}

}

}

// the called class MenuUI
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class MenuUI { //javax.swing.JFrame {
protected JLabel titleLabel = new JLabel("TEST");
protected JButton panelButtons = new JButton();
protected JButton menuButtons = new JButton();
private JPanel thisUI = new JPanel();


public void MenuUI() {
System.out.println("INIT2");
MenuUI("QBUS", 3, 3, 1, 8);
}


public void MenuUI(String title, int
panelButtonRowCount, int panelButtonColCount, int
menuButtonRowCount, int menuButtonColCount) {
// arguments aren't used for this example

try{
System.out.println("INIT2");

thisUI.setLayout( new BorderLayout() );

thisUI.add(titleLabel, BorderLayout.NORTH);
thisUI.add(panelButtons,
BorderLayout.CENTER);
thisUI.add(menuButtons, BorderLayout.SOUTH);

// panel end

thisUI.setSize( 240, 240);
} catch (Exception e)
{}
}

public JPanel getThePanel() {
return thisUI;
}

public void init() {
System.out.println("INIT");
}

}
 
P

Prosper

okay, I trimmed even more:

// QbusMenu.java
import javax.swing.*;
import java.awt.*;

public class QbusMenu extends JApplet {
MenuUI menuUI;

public void init(){
menuUI = new MenuUI();
this.getContentPane().add(menuUI.getThePanel() );
}

}


//MenuUI.java
import javax.swing.*;
import java.awt.*;

public class MenuUI {
JPanel thisUI = new JPanel();

public void MenuUI() {
thisUI.setLayout( new BorderLayout() );
thisUI.add(new JButton(),
BorderLayout.NORTH);
}

public JPanel getThePanel() {
return thisUI;
}
}
 
R

Ryan Stewart

Prosper said:
okay, I trimmed even more:

// QbusMenu.java
import javax.swing.*;
import java.awt.*;

public class QbusMenu extends JApplet {
MenuUI menuUI;

public void init(){
menuUI = new MenuUI();
this.getContentPane().add(menuUI.getThePanel() );
}

}


//MenuUI.java
import javax.swing.*;
import java.awt.*;

public class MenuUI {
JPanel thisUI = new JPanel();

public void MenuUI() {
thisUI.setLayout( new BorderLayout() );
thisUI.add(new JButton(),
BorderLayout.NORTH);
}

public JPanel getThePanel() {
return thisUI;
}
}

Very simply, your button isn't being added because you never call the method
to do so. Yes, that's a method, not a constructor. Remove the return type.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top