Problem in Constructor in JApplet
I try the following code to create a new class.
private Dept depts;
public void init()
depts = new Dept( "blah.." );
class Dept
public Dept( String strTemp )
I successfully compile it.
But when I try to run the applet, it gave me this error:
java.lang.NoSuchMethodError: Dept.<init>(Ljava/lang/String;)V
I have no idea what's that.
Please help me out here.
Thanks in advance.
The "<init>" means the constructor, which I guess you already knew.
Are you sure when you're using the latest compiled Dept.class when you run the applet?
Similar Messages
-
Hi guys im having problems with constructors. I get the following error:
package\Cat5500IfXDescr.java:60: cannot resolve symbol
symbol : constructor IfXDescrScanner(java.net.Inet,java.lang.String,java.lang.String,differentPackage.SNMPCommandObserver)
location: class package.IfXDescrScanner
super( InetAddress.getByName( device.getIpAddress()),
I have a class SNMPCommand
I have a class IfDescrScanner which extends SNMPCommand
I have a class Cat5500IfXDescr which extends IfDescrScanner
Here are the respective constructors:
public SNMPCommand( InetAddress agentAddress, String readCommunityString,
String writeCommunityString, SNMPCommandObserver observer ){
peer = new SnmpPeer( agentAddress );
peer.getParameters().setReadCommunity( readCommunityString );
peer.getParameters().setWriteCommunity( writeCommunityString );
this.observer = observer;
public SNMPCommand( InetAddress agentAddress, SNMPCommandObserver observer ){
peer = new SnmpPeer( agentAddress );
this.observer = observer;
public IfXDescrScanner(Device device, SNMPCommandObserver observer )
throws UnknownHostException{
super( InetAddress.getByName( device.getIpAddress()),
device.getReadCommunityString(),
device.getWriteCommunityString(),
observer );
public Cat5500IfXDescr( Device device, SNMPCommandObserver observer )
throws UnknownHostException{
super( InetAddress.getByName( device.getIpAddress()),
device.getReadCommunityString(),
device.getWriteCommunityString(),
observer );
}You'll notice SNMPCommand has 2 constructors. i get no error when i call super to the SNMPCommand constructor from IfXDescrScanner however when i call it from Cat5500IfXDescr i get the error. Is what i am doing illegal. Anyone any ideas on how i solve this. Thanks
Joe.From what I see in a single look, you are passing an object of java.net.Inet to the constructor and the constructor takes InetAddress object as parameter.
Just check it.
Hi guys im having problems with constructors. I get
the following error:
package\Cat5500IfXDescr.java:60: cannot resolve
symbol
symbol : constructor
IfXDescrScanner(java.net.Inet,java.lang.String,java.la
ng.String,differentPackage.SNMPCommandObserver)
location: class package.IfXDescrScanner
super( InetAddress.getByName(
device.getIpAddress()),
I have a class SNMPCommand
I have a class IfDescrScanner which extends
SNMPCommand
I have a class Cat5500IfXDescr which extends
IfDescrScanner
Here are the respective constructors:
public SNMPCommand( InetAddress agentAddress,
String readCommunityString,
String writeCommunityString,
tring, SNMPCommandObserver observer ){
peer = new SnmpPeer( agentAddress );
peer.getParameters().setReadCommunity(
y( readCommunityString );
peer.getParameters().setWriteCommunity(
y( writeCommunityString );
this.observer = observer;
public SNMPCommand( InetAddress agentAddress,
, SNMPCommandObserver observer ){
peer = new SnmpPeer( agentAddress );
this.observer = observer;
public IfXDescrScanner(Device device,
SNMPCommandObserver observer )
throws UnknownHostException{
super( InetAddress.getByName(
e( device.getIpAddress()),
device.getReadCommunityString(),
device.getWriteCommunityString(),
observer );
public Cat5500IfXDescr( Device device,
SNMPCommandObserver observer )
throws UnknownHostException{
super( InetAddress.getByName(
e( device.getIpAddress()),
device.getReadCommunityString(),
device.getWriteCommunityString(),
observer );
}You'll notice SNMPCommand has 2 constructors. i get
no error when i call super to the SNMPCommand
constructor from IfXDescrScanner however when i call
it from Cat5500IfXDescr i get the error. Is what i am
doing illegal. Anyone any ideas on how i solve this.
Thanks
Joe. -
Using constructors in JApplet for passing variables?
Hello,
Some how I could not figured out, how to pass some parameters to the JApplet by using the constructors. Some how none of the constructors are invoked when I run the JApplet. I have to run it without html. How can I solve this problem?public class K extends JApplet {
//declared variables here
public K() {
public K(Data data) {
System.out.println("******");
public K(int kNo) {
System.out.println("******");
setKNo(kNo);
public K(String kP) {
System.out.println("******");
setKP(kP);
public K(String kP, int kNo) {
System.out.println("******");
setKNo(kNo);
setKP(kP);
//init method works fine
public void init() {
this.setSize(500, 500);
this.setBackground(Color.BLACK);
this.setPreferredSize(new Dimension(500,500));
printer = new Printer(this);
panel = new Panel(this);
panel.repaint();
this.add(panel);
this.setVisible(true);
//Other Methods ....
}* I tried to invoke all of the constructors, I added System.out.println("******"); to see if the constructors work fine but none of the overriden constructors were invoked. * -
Problem with constructors and using public classes
Hi, I'm totally new to Java and I'm having a lot of problems with my program :(
I have to create constructor which creates bool's array of adequate size to create a sieve of Eratosthenes (for 2 ->n).
Then it has to create public method boolean prime(m) which returs true if the given number is prime and false if it's not prime.
And then I have to create class with main function which chooses from the given arguments the maximum and creates for it the sieve
(using the class which was created before) and returns if the arguments are prime or not.
This is what I've written but of course it's messy and it doesn't work. Can anyone help with that?
//part with a constructor
public class ESieve {
ESieve(int n) {
boolean[] isPrime = new boolean[n+1];
for (int i=2; i<=n; i++)
isPrime=true;
for(int i=2;i*i<n;i++){
if(isPrime[i]){
for(int j=i;i*j<=n;j++){
isPrime[i*j]=false;}}}
public static boolean Prime(int m)
for(int i=0; i<=m; i++)
if (isPrime[i]<2) return false;
try
m=Integer.parseInt(args[i]);
catch (NumberFormatException ex)
System.out.println(args[i] + " is not an integer");
continue;
if (isPrime[i]=true)
System.out.println (isPrime[i] + " is prime");
else
System.out.println (isPrime[i] + " is not prime");
//main
public class ESieveTest{
public static void main (String args[])
public static int max(int[] args) {
int maximum = args[0];
for (int i=1; i<args.length; i++) {
if (args[i] > maximum) {
maximum = args[i];
return maximum;
new ESieve(maximum);
for(int i=0; i<args.length; i++)
Prime(i);}I've made changes and now my code looks like this:
public class ESieve {
ESieve(int n) {
sieve(n);
public static boolean sieve(int n)
boolean[] s = new boolean[n+1];
for (int i=2; i<=n; i++)
s=true;
for(int i=2;i*i<n;i++){
if(s[i]){
for(int j=i;i*j<=n;j++){
s[i*j]=false;}}}
return s[n];}
public static boolean prime(int m)
if (m<2) return false;
boolean x = sieve(m);
if (x=true)
System.out.println (m + " is prime");
else
System.out.println (m + " is not prime");
return x;}
//main
public class ESieveTest{
public static int max(int[] args) {
int maximum = args[0];
for (int i=1; i<args.length; i++) {
if (args[i] > maximum) {
maximum = args[i];
return maximum;
public static void main (String[] args)
int n; int i, j;
for(i=0;i<=args.length;i++)
n=Integer.parseInt(args[i]);
int maximum=max(args[]);
ESieve S = new ESieve(maximum);
for(i=0; i<args.length; i++)
S.prime(i);}
It shows an error for main:
{quote} ESieveTest.java:21: '.class' expected
int maximum=max(args[]); {quote}
Any suggestions how to fix it? -
Swing layout/size problem with JFrame and JApplet.
I have a class that extends a JFrame, the classes layout is BorderLayout. I then have a class that extend JApplet, this classes layout is GridBagLayout (this class has a JTabbedPane - which contains JPanels). The problem I'm having is no matter how big I make the size of the applet or frame (using setSize), the applet/frame stays the same size - no matter how large I make it.
Can anyone please help?
Thanks,
dosteovHere is the basic code:
Thanks in advance,
dosteov
public class EADAdm extends JApplet
EADAdmFrame theFrame = new EADAdmFrame(this);
public void init()
// Take out this line if you don't use symantec.itools.net.RelativeURL or symantec.itools.awt.util.StatusScroller
// symantec.itools.lang.Context.setApplet(this);
// This line prevents the "Swing: checked access to system event queue" message seen in some browsers.
getRootPane().putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE);
// This code is automatically generated by Visual Cafe when you add
// components to the visual environment. It instantiates and initializes
// the components. To modify the code, only use code syntax that matches
// what Visual Cafe can generate, or Visual Cafe may be unable to back
// parse your Java file into its visual environment.
//{{INIT_CONTROLS
getContentPane().setLayout(new GridBagLayout());
setEnabled(false);
getContentPane().setBackground(java.awt.Color.lightGray);
setSize(800,800);
getContentPane().add(AdmTab, new com.symantec.itools.awt.GridBagConstraintsD(0,1,2,1,0.5,0.5,java.awt.GridBagConstraints.CENTER,java.awt.GridBagConstraints.HORIZONTAL,new Insets(3,12,4,14),120,120));
AdmTab.setFont(new Font("Dialog", Font.PLAIN, 12));
titleLbl.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
titleLbl.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
titleLbl.setText("EAD Administration");
getContentPane().add(titleLbl, new com.symantec.itools.awt.GridBagConstraintsD(0,0,1,1,0.0,0.0,java.awt.GridBagConstraints.CENTER,java.awt.GridBagConstraints.NONE,new Insets(12,36,0,0),307,15));
titleLbl.setForeground(java.awt.Color.blue);
titleLbl.setFont(new Font("Dialog", Font.BOLD, 15));
exitBtn.setText("Exit EAD Administration");
exitBtn.setActionCommand("Exit EAD Administration");
getContentPane().add(exitBtn, new com.symantec.itools.awt.GridBagConstraintsD(0,2,2,1,0.0,0.0,java.awt.GridBagConstraints.CENTER,java.awt.GridBagConstraints.NONE,new Insets(6,371,10,14),66,8));
exitBtn.setFont(new Font("Dialog", Font.PLAIN, 12));
//theFrame.setVisible(false);
login();
AdmTab.addTab("Administration", new LogoPanel() );
userPanel = createUserPanel();
AdmTab.addTab("Edit Users", userPanel );
fpoPanel = createFPOPanel();
AdmTab.addTab("Edit FPO", fpoPanel );
regulationPanel = createRegulationPanel();
AdmTab.addTab("Edit Regulations", regulationPanel );
rolloverPanel = createRolloverPanel();
AdmTab.addTab("Rollover", rolloverPanel );
//{{REGISTER_LISTENERS
SymMouse aSymMouse = new SymMouse();
this.addMouseListener(aSymMouse);
SymAction lSymAction = new SymAction();
exitBtn.addActionListener(lSymAction);
SymKey aSymKey = new SymKey();
this.addKeyListener(aSymKey);
theFrame.getContentPane().add(this);
public class EADAdmFrame extends JFrame
EADAdm theApplet;
public EADAdmFrame(EADAdm theMainApplet)
//{{INIT_CONTROLS
// theApplet = theMainApplet;
// this.getContentPane().add(theApplet);
getContentPane().setLayout(new BorderLayout(0,0));
getContentPane().setBackground(java.awt.Color.lightGray);
setSize(1000,1000);
setVisible(false);
theApplet = theMainApplet;
//{{REGISTER_LISTENERS
SymWindow aSymWindow = new SymWindow();
this.addWindowListener(aSymWindow);
SymComponent aSymComponent = new SymComponent();
this.addComponentListener(aSymComponent); -
Problem with Thread in JApplet
Hi,
I am working on a project on pseudo random functions, and for that matter I have written a problem. Now I am working on a user interface (JApplet) for my program. Because some heavy calculations can occur, I want to keep track of the progress, and show that in my JApplet. To do so, I start a Thread in which the calculations take place. In my JApplet I want to show every second how far the proces is done. The strange thing is, that the status JLabel only appears when the whole proces is done, and the start button keeps pressed during the proces. If I run this in the applet viewer, I can see the status every second in my command box. You can see the applet here : applet
The code concerning the start button's actionlistener (entire appletcode: [applet code|http://www.josroseboom.nl/PseudoRandomClusteringApplet.java]) :
if(e.getSource()==start)
int[][] randomFuncties = new int[current+1][5];
int puntenHuidige, g, q, y, m, f;
boolean done;
Kern k;
for(int i = 0;i<=current;i++)
randomFuncties[i] = functies.getValues();
invoer.remove(knopjes);
startTijd = System.currentTimeMillis();
proces.setBounds(25,(current+4)*25, 2*this.getWidth()/3,75);
invoer.add(proces);
this.validate();
this.repaint();
for(int i = 0;i<=current;i++)
puntenHuidige = 0;
f = randomFuncties[i][0]; // important for instantiation of k, which is cut out here
done = false;
k.start(); // k is a Thread where heavy calculations are done
((JLabel)(proces.getComponent(2))).setText("points done of current (" + q + ")");
this.repaint();
while(!done)
((JLabel)(proces.getComponent(1))).setText("" + convertTime(System.currentTimeMillis() - startTijd));
((JLabel)(proces.getComponent(3))).setText("" + k.getPuntenGehad()); // get the point done so far
((JLabel)(proces.getComponent(5))).setText("" + ((100*k.getPuntenGehad())/q) + "%");
debug("q: " + q);
debug("point done: " + k.getPuntenGehad());
if(k.getPuntenGehad()==q) //if all points are considered
done=true;
this.validate();
this.repaint();
try
Thread.sleep(1000);
catch(InterruptedException exception)
debug("foutje met slapen: InterruptedException");
catch(IllegalMonitorStateException exception)
debug("foutje met wachten: IllegalMonitorStateException");
debug("IN APPLET: yet another loop walk");
stringResultaten.add(k.geefResultaat());
klaarLabel.setBounds(this.getWidth()/4,(current+8)*25, this.getWidth()/2,25);
naarResultaat.setBounds(25+this.getWidth()/4,(current+9)*25, this.getWidth()/4,25);
invoer.add(klaarLabel);
invoer.add(naarResultaat);
this.validate();
this.repaint();
Edited by: Jos on Sep 19, 2007 1:22 AMNever do anything that takes more than a fraction of a second in an actionPerformed method or similar GUI callback.
The GUI stuff is all handled by a single thread called the "AWT Dispatcher" thread. That includes code in such callbacks. While it's executing your callback it can't do any kind of screen updating or response to other user events.
Instead your actionPerformed should work with a separater "worker" thread, either it should launch a new thread, or release one you create (using wait and notify). Then, it returns without waiting. When the worker thread wants to update the GUI it uses EventQueue.invokeLater() or invokeAndWait() to run some (fast) code on the Dispatcher thread. -
Hi guys
when i created this constructor, it keep throwing back this error whcih i don't understand.
public interface MyNumber {
// data defination
private int wholenumber = 0;
private float fraction = 0;
// constructor
public MyNumber(int whole, float fract) {
wholenumber = whole;
fraction = fract;
may i know what is wrong with my constructor code?
it keep saying <identifier>> expectedpart b of the question has ask for an interface class
any problem with my code?
public class MyNumber {
// data defination
private int wholenumber = 0;
private float fraction = 0;
// constructor
public MyNumber(int whole, float fract) {
wholenumber = whole;
fraction = fract;
// methods or operations
public MyNumber add(MyNumber c, MyNumber d){
int r = wholenumber + c.getWholeNumber();
float i = fraction + c.getFraction();
MyNumber newC = new MyNumber(r,i);
//MyNumber newD = new MyNumber(i);
return newC;
//return newD;
public MyNumber subtract(MyNumber c, MyNumber d){
int r = wholenumber - c.getWholeNumber();
float i = fraction - c.getFraction();
MyNumber newC = new MyNumber(r,i);
//MyNumber newD = new MyNumber(i);
return newC;
//return newD;
public MyNumber multiply(MyNumber c, MyNumber d){
int r = wholenumber * c.getWholeNumber();
float i = fraction * c.getFraction();
MyNumber newC = new MyNumber(r,i);
//MyNumber newD = new MyNumber(i);
return newC;
//return newD;
public int getWholeNumber(){
return wholenumber;
public float getFraction(){
return fraction;
} -
Problem while loading a JApplet ( which uses JAI ) on Netscape across ssl
Hi Folks...
I m having some problem in applet.. can any1 of u guys help me???? My problem is as follows..
I m having 2 JApplets (Swing applet) one of the applet is using JAI (Java Advance Imaging APIs). I m trying 2 load both the applets in IE as well as in Netscape across SSL (ie thru https protocol) .Both the applet can be loaded on IE across SSL. but when i m trying to load the applet on Netscape, one of the applet which is using JAI is not getting loaded across SSL. The other applet which is not using JAI is running fine across SSL on Netscape also.
I m getting some exception.. Is this exception comming bcoz JAI is not compatible with Netscape r bcoz of somethinf else??? If it is bcoz of the fact that Netscape does'nt have any support for JAI across SSL. then watz the possible solution 4 that. How can i overcome by this problem. Its very urgent.. i need to do it any how... Plz plz help me out if u guys have any idea abt this.. any help is most welcome..
My ids r
[email protected]
[email protected]
tks...
JameelExactly what exception are you getting? That will really help in determining the problem. Also, do you have the same problems when going over a regular connection (i.e. not over SSL)?
Kate -
Problems updating gui in JApplet
Hi,
I have a JApplet with a JPanel with another JPanel ? TreePanel ? containing a JScrollPane with a JTree.
When init() is run in MyApplet, treePanel is initiated with a JTree, with test data hardcoded in TreePanel?s constructor. I want the tree to change every time a thread loops, by calling method treePanel.updateResultTree(root) from the thread, with a new root. To test this, I have hardcoded a new tree content in the thread to pass to the TreePanel. In method updateResultTree(root), I remove the existing JTree from JScrollPane and add a new JTree to it, with the new root. Then I repaint the JScrollPane.
When I run the applet, the initial tree is displayed, but it is not updated with the new JTree for the first thread loop as expected. How is the gui in a JApplet refreshed/updated?? Will SwingWoker update the gui automatically without forcing repaint()?
Please help, I'm so stuck! Thanks in advance!
MyApplet
public class MyApplet extends JApplet {
private TreePanel _treePanel;
private UpdateHandler _updateHandler;
private Thread _updateThread;
public void init() {
super.init();
_treePanel = new TreePanel();
// Updating thread
_updateHandler = new UpdateHandler();
_updateThread = new Thread(_updateHandler);
_updateThread.start();
// Initialize gui
JPanel bigPanel = new JPanel();
bigPanel.setLayout(new BoxLayout(bigPanel, BoxLayout.X_AXIS));
getContentPane().add(bigPanel, BorderLayout.CENTER);
_treePanel = new JPanel();
bigPanels.add(_treePanel);
// Updates the GUI every X seconds
private class UpdateHandler implements Runnable {
public final static int UPDATE_INTERVAL = 10;
public UpdateHandler() { }
public void run() {
try {
_displayResults();
} catch (InterruptedException ie) {
private synchronized void _ displayResults () throws InterruptedException {
while(true) {
// Resolve a new DefaultMutableTreeNode object as root to be updated in GUI
// (For test)
DefaultMutableTreeNode root = new DefaultMutableTreeNode(new Result("Root"));
DefaultMutableTreeNode child_1 = new DefaultMutableTreeNode(new Result("Result X"));
DefaultMutableTreeNode child_2 = new DefaultMutableTreeNode(new Result("Result Y"));
DefaultMutableTreeNode child_11 = new DefaultMutableTreeNode(new Result("Result X1"));
root.add(child_1);
root.add(child_2);
child_1.add(child_11);
// Update the GUI
_treePanel.updateTree(root);
wait(UPDATE_INTERVAL*1000);
}TreePanel
public class TreePanel extends JPanel {
private JScrollPanel _treeSrcoll;
private JTree _tree;
TreePanel() {
super();
// Test tree, displayed in applet?s init()
DefaultMutableTreeNode root = new DefaultMutableTreeNode (new Result("Root"));
DefaultMutableTreeNode child_1 = new DefaultMutableTreeNode (new Result("Result 1"));
DefaultMutableTreeNode child_2 = new DefaultMutableTreeNode (new Result("Result 2"));
DefaultMutableTreeNode child_11 = new DefaultMutableTreeNode (new Result("Result 4"));
DefaultMutableTreeNode child_12 = new DefaultMutableTreeNode (new Result("Result 5"));
root.add(child_1);
root.add(child_2);
child_1.add(child_11);
child_1.add(child_12);
_tree = new JTree(root);
_treeScroll = new JScrollPane(_tree);
add(_treeScroll, BorderLayout.CENTER);
public void updateTree(DefaultMutableTreeNode theRoot) {
if (theRoot != null) {
if (_tree!= null) {
_treeScroll.remove(_tree);
_ tree = new QCTree(root);
_treeScroll.add(_tree);
} else {
JLabel label = new JLabel("No result tree structure is available");
_treeScroll.add(label);
_treeScroll.repaint();
}Result
public class Result {
private String _name;
public Result(String name) {
_name = name;
public String toString() {
return _name;I found the error:
I need to use
treeScroll.getViewPort().add(tree);
and
treeScroll.getViewPort().remove(tree); -
Problem with constructor of inner class.
Hi everybody!
I have an applet which loads images from a database.
i want to draw the images in a textarea, so i wrote an inner class, which extends textarea and overrides the paint method.
but everytime i try to disply the applet in the browser this happens:
java.lang.NoClassDefFoundError: WohnungSuchenApplet$Malfl�che
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:1590)
at java.lang.Class.getConstructor0(Class.java:1762)
at java.lang.Class.newInstance0(Class.java:276)
at java.lang.Class.newInstance(Class.java:259)
at sun.applet.AppletPanel.createApplet(AppletPanel.java:567)
at sun.plugin.AppletViewer.createApplet(AppletViewer.java:1778)
at sun.applet.AppletPanel.runLoader(AppletPanel.java:496)
at sun.applet.AppletPanel.run(AppletPanel.java:293)
at java.lang.Thread.run(Thread.java:536)
so my class has no own constructor, it just has the paint method overwritten.
my class looks like this:
public class Malfl�che extends javax.swing.JTextArea{
public void paint(Graphics g){
Color grey=new Color(220,220,220);
g.drawImage(img,10,10,null);
how should a constructor for this class look like?
sorry i am quite new to this, so i really dont have a clue!
my class does not have any attributes or requires any so it doesnt need a constructor, doesnt it?
thanks a lot
timFirst off, unlike regular classes, inner classes can be declared public, private, protected, and default.
Secondly, why are you using the JTextArea to display an image, why not use a JLabel, which takes an Image object as its constructor.
Thirdly, when you drew your image you did not give it a width and height
g.drawImage(img, 0,0, img.getWidth(null), img.getHeight(null), null);
otherwise it will make your image 1 X 1 pixels. not big enough to see. -
What is the problem with constructor?......
class sam
private String name;
private String desgn;
public sam(String s){ name=s; }
public void showName(){ System.out.println(" Name "+name); }
public void setDesgn(String d){ desgn=d; }
public void showDesgn(){ System.out.println(" Designation "+desgn); }
class samp1 extends sam {
private String Name;
private String degree;
public samp1(String s){
Name=s;
public void showName(){ System.out.println(" Name "+Name); }
public void setDegree(String d){ degree=d; }
public void showDegree(){ System.out.println(" Degree "+degree); }If you want the sam constructor to be called you'll
have to put in
super(s);To elaborate a bit...
Here are the rules for constructors--"ctors" because I'm lazy. Also, because I'm lazy, "super(...)" and "this(...)" mean any super or this call, regardless of how many args it takes, including those that take no args.
1) Every class has at least one ctor.
1.1) If you do not define an explicit constructor for your class, the compiler provides a implicit constructor that takes no args and simply calls super().
1.2) If you do define one or more explicit constructors, regardless of whether they take args, then the compiler no longer provides the implicit no-arg ctor. In this case, you must explicitly define a public MyClass() {...} if you want one.
1.3) Constructors are not inherited.
2) The first statement in the body of any ctor is either a call to a superclass ctor super(...) or a call to another ctor of this class this(...) 2.1) If you do not explicitly put a call to super(...) or this(...) as the first statement in a ctor that you define, then the compiler implicitly inserts a call to super's no-arg ctor super() as the first call. The implicitly called ctor is always super's no-arg ctor, regardless of whether the currently running ctor takes args.
2.2) There is always exactly one call to either super(...) or this(...) in each constructor, and it is always the first call. You can't put in more than one, and if you put one in, the compiler's implicitly provided one is removed. -
Problem accessing database from JApplet
Hi all,
I am having trouble in changing my application to Japplet. It displaying the frame in web page but when i am trying to access database it is not displaying anything. Please let me know if any one know the solution. Thank you.
bestpro.It is hard to say since you didn't post any exceptions you are getting but I would venture to guess you are getting a security exception and you need to sign your applet so your applet can play outside of the security sandbox and connect to your db server.
Hit google and search for "signing applets" or something similiar and it should put you on the right path. -
Problems with constructors? can anyone help
I want to use the Math.random() class to generate a random number
to fill an array.In the 2 constructors i have this:
private int[] rand;
public Randomize(int ra[])
{rand = new int[7];}
public Randomize()
{Math.random();}
*note ra is a formal parameter
but nothing happens. The array rand does not fill up with random numbers
how can i fill it up with random numbers?Hi Mike,
The Math.random() is a static method that returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0.
It does not return an array or a int. If you use the Math.random method, you will have to cast your double into an int. Also you need to create a for loop to fill your array and add code to check that the value returned from the Math.random method has not already been used. -
Hi there all:
I'm having a problem with debugging a JApplet. I created a new workspace, project and applet and didn't make any changes to anything. When I try to debug the applet, I get these messages:
System Error: java.security.AccessControlException: access denied (java.lang.RuntimePermission modifyThreadGroup )
System Error: java.lang.Object java.lang.Class.newInstance0()
System Error: java.lang.Object java.lang.Class.newInstance()
System Error: java.applet.Applet sun.applet.AppletPanel.createApplet(sun.applet.AppletClassLoader)
System Error: void sun.applet.AppletPanel.runLoader()
System Error: void sun.applet.AppletPa
System Error: nel.run()
System Error: void java.lang.Thread.run()
If I change the object from a JApplet class to an Applet class, I can debug just fine.
Anyone know what's going on here?
Thanks
JeffMe again. Was doing some searching on the net about this one since I've gotten no response.
Found this at Inprise (Borland) about a debugging problem with JBuilder3 (I assume that the base of jdev is still JBuilder).
http://community.borland.com/article/0,1410,19739,00.html
To quote from their document--------
Question:
I can't seem to debug Applets with JBuilder3 Standard. If I attempt to debug my Applet
I recieve the following error:
java.security.AccessControlException: access denied (java.lang.RuntimePermission
modifyThreadGroup )
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:195)
at java.security.AccessController.checkPermission(AccessController.java:403)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
Why?
Answer:
In a nutshell this is an installation problem with JBuilder3 Standard edition.
The install for JBuilder3 Standard did not provide the file 'DebugApplet.policy'.
To resolve this problem download the file from the following URL:
http://www.borland.com/devsupport/jbuilder/downloads/DebugApplet.policy
After you have downloaded the file, copy the file to your JBuilder3\bin directory.
This will fix the problem.
You can also cut and paste the following:
(NOTE: create the file DebugApplet.policy in your JBuilder3\bin directory)
//DebugApplet.policy
// These policy permissions are needed for the AppletViewer used by sun.tools.debug.
grant {
permission java.lang.RuntimePermission "accessClassInPackage.*";
permission java.lang.RuntimePermission "modifyThread";
permission java.lang.RuntimePermission "modifyThreadGroup";
permission java.net.SocketPermission "*", "accept, connect, listen, resolve";
permission java.util.PropertyPermission "appletviewer.version", "read";
permission java.io.FilePermission "<>", "read";
permission java.security.AllPermission;
Could this be a problem in JDev3 too?
Jeff
null -
Pls help..Constructor,setter, getter and Exception Handling Problem
halo, im new in java who learning basic thing and java.awt basic...i face some problem about constructor, setter, and getter.
1. I created a constructor, setter and getter in a file, and create another test file which would like to get the value from the constructor file.
The problem is: when i compile the test file, it come out error msg:cannot find symbol.As i know that is because i miss declare something but i dont know what i miss.I post my code here and help me to solve this problem...thanks
my constructor file...i dont know whether is correct, pls tell me if i miss something...
public class Employee{
private int empNum;
private String empName;
private double empSalary;
Employee(){
empNum=0;
empName="";
empSalary=0;
public int getEmpNum(){
return empNum;
public String getName(){
return empName;
public double getSalary(){
return empSalary;
public void setEmpNum(int e){
empNum = e;
public void setName(String n){
empName = n;
public void setSalary(double sal){
empSalary = sal;
my test file....
public class TestEmployeeClass{
public static void main(String args[]){
Employee e = new Employee();
e.setEmpNum(100);
e.setName("abc");
e.setSalary(1000.00);
System.out.println(e.getEmpNum());
System.out.println(e.getName());
System.out.println(e.getSalary());
}**the program is work if i combine this 2 files coding inside one file(something like the last part of my coding of problem 2)...but i would like to separate them....*
2. Another problem is i am writing one simple program which is using java.awt interface....i would like to add a validation for user input (something like show error msg when user input character and negative number) inside public void actionPerformed(ActionEvent e) ...but i dont have any idea to solve this problem.here is my code and pls help me for some suggestion or coding about exception. thank a lots...
import java.awt.*;
import java.awt.event.*;
public class SnailTravel extends Frame implements ActionListener, WindowListener{
private Frame frame;
private Label lblDistance, lblSpeed, lblSpeed2, lblTime, lblTime2, lblComment, lblComment2 ;
private TextField tfDistance;
private Button btnCalculate, btnClear;
public void viewInterface(){
frame = new Frame("Snail Travel");
lblDistance = new Label("Distance");
lblSpeed = new Label("Speed");
lblSpeed2 = new Label("0.0099km/h");
lblTime = new Label("Time");
lblTime2 = new Label("");
lblComment = new Label("Comment");
lblComment2 = new Label("");
tfDistance = new TextField(20);
btnCalculate = new Button("Calculate");
btnClear = new Button("Clear");
frame.setLayout(new GridLayout(5,2));
frame.add(lblDistance);
frame.add(tfDistance);
frame.add(lblSpeed);
frame.add(lblSpeed2);
frame.add(lblTime);
frame.add(lblTime2);
frame.add(lblComment);
frame.add(lblComment2);
frame.add(btnCalculate);
frame.add(btnClear);
btnCalculate.addActionListener(this);
btnClear.addActionListener(this);
frame.addWindowListener(this);
frame.setSize(100,100);
frame.setVisible(true);
frame.pack();
public static void main(String [] args) {
SnailTravel st = new SnailTravel();
st.viewInterface();
public void actionPerformed(ActionEvent e) {
if (e.getSource() == btnCalculate){
SnailData sd = new SnailData();
double distance = Double.parseDouble(tfDistance.getText());
sd.setDistance(distance);
sd.setSpeed(0.0099);
sd.setTime(distance/sd.getSpeed());
String answer = Double.toString(sd.getTime());
lblTime2.setText(answer);
lblComment2.setText("But No Exception!!!");
else
if(e.getSource() == btnClear){
tfDistance.setText("");
lblTime2.setText("");
public void windowClosing(WindowEvent e){
System.exit(1);
public void windowClosed (WindowEvent e) { };
public void windowDeiconified (WindowEvent e) { };
public void windowIconified (WindowEvent e) { };
public void windowActivated (WindowEvent e) { };
public void windowDeactivated (WindowEvent e) { };
public void windowOpened(WindowEvent e) { };
class SnailData{
private double distance;
private double speed;
private double time;
public SnailData(){
distance = 0;
speed = 0;
time = 0;
public double getDistance(){
return distance;
public double getSpeed(){
return speed;
public double getTime(){
return time;
public void setDistance(double d){
distance = d;
public void setSpeed(double s){
speed = s;
public void setTime(double t){
time = t;
}Pls and thanks again for helps....What i actually want to do is SnailTravel, but i facing some problems, which is the
- Constructor,setter, getter, and
- Exception Handling.
So i create another simple contructor files which name Employee and TestEmployeeClass, to try find out the problem but i failed, it come out error msg "cannot find symbol".
What i want to say that is if i cut below code (SnailTravel) to its own file(SnailData), SnailTravel come out error msg "cannot find symbol".So i force to put them in a same file(SnailTravel) to run properly.
I need help to separate them. (I think i miss some syntax but i dont know what)
And can somebody help me about Exception handling too pls.
class SnailData{
private double distance;
private double speed;
private double time;
public SnailData(){
distance = 0;
speed = 0;
time = 0;
public double getDistance(){
return distance;
public double getSpeed(){
return speed;
public double getTime(){
return time;
public void setDistance(double d){
distance = d;
public void setSpeed(double s){
speed = s;
public void setTime(double t){
time = t;
}
Maybe you are looking for
-
How to insert subtype data from another table in a object table ?
Hi all I have been looking at the differences answers there are about insert data form a subtype in a object table of a supertype ,but have not found a solution yet. I hope you can help me. I my code Action_Logs is the object table and CloseStore_Log
-
HP ENVY TouchSmart m7t-j000 Notebook PC - Adding a second hard drive
Product Number: E4S80AV I'm having a hard time finding a SATA III cable and caddy for a second hard drive for my laptop. Any ideas? Right now, I just have an extra 1.8 inch drive I can't use. Robert
-
Payment term working in FB60 but not in MIRO
Hi Friends, I have a payment term due next month on a fixed date from invoice date. I see the results are perfectly fine when posting the vendor invoice in FB60. while in case of MIRO, it does not. In miro it makes the baseline date as due date. Is t
-
How do you restore hidden photos in iPhoto
i accidentally hid some photos and now I want to restore them. any help?
-
IMac screen went black. What now?
All was working well and then the screen on my iMac went black. PRAM reset did not help. Restarting indicated that the computer was on but the screen was black. Any suggestions? I am running a 27" iMac, 10.5.8 OS.