Question on declaring an object initialized in a constructor
Anyone knwo what is wrong with the winappFrame line below? It's from a book I'm following along and it errors in my IDE.
public class winapp extends java.applet.Applet {
public static void main(String[] args) {
winappFrame frame = new winappFrame("System Status");
frame.resize(400, 300);
winapp applet = new winapp();
frame.add("Center", applet);
applet.init();
applet.start();
frame.show();
public void paint(Graphics g) {
g.drawString("The system is currently down", 60, 30);
class winappFrame extends Frame {
public winappFrame(String str) {
super (str);
public boolean handleEvent(Event evt) {
switch(evt.id) {
case Event.WINDOW_DESTROY:
dispose();
System.exit(0);
return true;
default:
return super.handleEvent(evt);
}
Your error message in Reply #2 (don't know why it says textfields, but ...) means:
winappFrame class only exists inside an instance of winapp. So, try this:
Instead of what you have:
winappFrame frame = new winappFrame("System Status"); // 1
frame.resize(400, 300); // 2
winapp applet = new winapp(); // 3Do this:
winapp applet = new winapp(); // 3 [above]
winappFrame frame = applet.new winappFrame("System Status"); // 1 above [note change]
frame.resize(400, 300); // 2 [above]
Similar Messages
-
Question about declaring type as interface
Hi
I am trying to get my head around declaring an object as the interface type (I think this is right correct me if I am wrong). Ok so I understand if I declare my object reference as the interface I will only get the methods of the interface defined in the objects class..? ie
List myList = new ArrayList();I think any method particular to ArrayList will not be there. But I dont actually understand wha is happening here, I have a ref to a List but the object is actually an ArrayList?
So if I passed ths list to a session object and got it out I could cast it back to the interface. I dont understand why or what is happening here.
I hope someone understands my question enough that they can help me out, this has been nugging me for a while.
ThanksI am trying to get my head around declaring an object
as the interface type (I think this is right correct
me if I am wrong). Ok so I understand if I declare my
object reference as the interface I will only get the
methods of the interface defined in the objects
class..? ie
List myList = new ArrayList();I think any method particular to ArrayList will not
be there. If you use myList without casting, then, yes, only List's methods will be available, because all the compiler knows is that it's a reference to a List. It doesn't know that at runtime it will point to an ArrayList object.
You could cast myList to ArrayList to get ArrayList-specific things (if there are any), but a) if you're not careful, you can end up with a ClassCastException at runtime (you won't here, but in general you can) and b) if you're going to do that, you have to question why you declared it as a List in the first place. There are cases where casting is appropriate, but you have to be careful.
But I dont actually understand wha is
happening here, I have a ref to a List but the object
is actually an ArrayList?Yes.
So if I passed ths list to a session object and got
it out I could cast it back to the interface. I dont
understand why or what is happening here.You could cast it to anything that the object actually is, that is, any of its superclasses and superinterfaces. If it's an ArrayList, you could cast it to any of the following: ArrayList, AbstractList, AbstractCollection, Object, Serializable, Cloneable, Iterable, Collection, List, RandomAccess. -
hello...my questions is related to objective C..
Is it possible to display name of the person who is calling me whose number is saved in my local database but not in iphone contacts ?.ashish35,
No one from Apple here - we're just users like you. All I can tell you is that electronic fail and with MacBook Pros (and most notebooks) the components are so integrated as to make a repair to the logic board practically impossible, hence the high prices charged for repairs.
Only you can decide if you want to have your computer repaired or put the money towards the purchase of a new computer. If you do decide to purchase a new unit I would suggest that you also purchase the AppleCare Protection Plan which increases your warranty from one year to three years.
Sorry and good luck,
Clinton -
So how do you declare an object?
Okay I have a program I'm trying to build that lets me navigate between menus...
Main Menu starts up:
(Unimportant)
Then it takes me to another Menu.
When this is over I want to go back:
System.out.println("Select: ");
System.out.println("1: to Return to the main menu");
System.out.println("or");
System.out.println("0 to Exit");
if(input.nextInt()==1){
main(); // <-- error here
else if(input.nextInt()==0){
System.exit(0);
} It doesnt find the main method because I didn't declare it as an object at the top...
How do I do that?
Edited by: tark_theshark on Mar 30, 2008 5:24 AMNah, this has nothing to do with declaring an object, and you really don't want to do this. What you really want to do is to have a loop of some kind, say a while loop and have the loop repeat until the user presses "0". Something like so:
public static void main(String[] args)
boolean done = false;
while (!done)
if(input.nextInt() == 0)
done = true;
}Edited by: Encephalopathic on Mar 30, 2008 6:27 AM -
Lost objectives, initiatives and milestones in SSM
I have lost the objectives, initiatives and milestones after delete the application group.
We have created a demo enviroment for a client demo.
Created the context, application groups, perspectives, objectives, initiatives and milestones in SSM Administrator's user interface.
Initiatives are created with the correspondings applications groups.
We realized that the applications groups weren't linked with any the SAP Netweaver UME system group. Then we deleted the applications groups in SSM Administrator's user interface in order to create them correctly.
After that we see that the objectives, initiatives and milestones don't appear in the SSM > Initiatives tab. The strange thing is that we can see objectives and initiatives when clicking on the goal diagram.
We think that after deleting the application group the values where deleted from the initiatives, milestones, etc.
How can we recover initiatives, milestones, etc?Thank you for your answer Bob.
I would like to update the information posted. I only lost initiatives and milestones (not objectives) after delete an application group.
I understand when you say if you delete an application group you loose initiatives asociated to. It was what happened to me. But the strange thing is that although the initiatives aren't in the Initiatives tab I am still seeing them when I clicking on the goal diagram.
If I click on the initiative link on the goal diagram a error message appears: "Cannot display linked inititative contact your System administrator. Initiative may have been deleted, or you may not have permission to view it".
Do you know how it is possible to view the "old initiatives" in the goal diagram if they were deleted? Are the initiaves still saved in the server?
Regards,
Santiago -
Can we declare primary as initially deferred deferrable
Hi,
Anyone know Can we declare primary as initially deferred deferrable...What is the syntax like?
Thank You....Left's first look at the approach you use.. 2 SQL statements that can be done using a single SQL statement.
Actually it is not as bad as some other code posted here where people go and write complex PL/SQL code to do what could have been done using a single SQL statement.
There are a couple of golden rules in Oracle development. One of these is to 'Maximise SQL and Minimise PL/SQL'.
Why take a value from one SQL statement into PL/SQL and then use that value in a second SQL statement?
Rather do this:
select
fn into n
from table2
where id like (Select a from table1 where b like b_new);Also keep in mind that in PL/SQL the above SQL construct is only able to fetch a single row - look at the bold above. The variable N can only hold a single value. If that SQL SELECT returns more than one value, how is variable N suppose to hold it?
I suggest that you read [url http://www.oracle.com/pls/db102/to_toc?pathname=appdev.102%2Fb14261%2Ftoc.htm&remark=portal+%28Books%29]Oracle® Database PL/SQL User's Guide and Reference guide. -
Puzzle about declare List object
Why we declare a object using "List list=new ArrayList();" other than "ArrayList list=new ArrayList();"?I have seen in Java API that:"Source source=new StreamSource();" other than "StreamSource souce=new StreamSource();".Is there any advantages to do this?
just gives you more flexibility when you may possibly change the instance of the object being created.... more like the Factory patteren....
hmmm.... i dont think im making much sence here.... :O)) let me explain with an example....
the return type of Calendar.getInstance() is Calendar while internally it actually returns an instance of GregorianCalendar which is a sub-class of the Calendar class... the reason to that all the methods that you want are available in the Calendar class, & if a couple of version down the road if the API changes to return an instance of some other sub-class of Calendar, anyone using it would not be effected....
BUT if in your case you are using specific methods that are only available in the ArrayList and not in the List class.... then you would be better off using ArrayList list=new ArrayList()....
hope this explains to some extent
regards
omer -
Question about the Timer Objects
According to the API docs, the method Schedule for a Timer object takes the following constructor:
schedule
public void schedule(TimerTask task,
Date time)
Schedules the specified task for execution at the specified time. If the time is in the past, the task is scheduled for immediate execution.
Parameters:
task - task to be scheduled.
time - time at which task is to be executed.
Source: [link]http://java.sun.com/j2se/1.4.2/docs/api/java/util/TimerTask.html[link]
However, I am getting the following error:
The method Schedule(TimerTask, Date) is undefined for the type Timer.
Any idea why I would be getting this message?However, I am getting the following error:
The method Schedule(TimerTask, Date) is undefined for
the type Timer.
Any idea why I would be getting this message?Yeah. Could be 2 things:
1. It's "schedule" not "Schedule" (case matters)
2. You're using java.sql.Data instead of java.util.Date. -
Question about declare and create an object
There are 2 classes and one is subclass of another like below:
class A { }
class B extends A {
1. A x = new B(); // x is a *reference variable* of class A and it points to( refer to) an *object* of class B
2. B x = new A(); // x is a *reference variable* of class B and it points to( refer to) an *object* of class A
} The first one is correct one but the second. I do not have a good explanation for that. The only thing I just know is just because B extends A. Im not convinced myself. Pls help, thanks
Edited by: newbie on Oct 25, 2010 11:03 PM
Edited by: newbie on Oct 25, 2010 11:26 PMnewbie wrote:
There are 2 classes and one is subclass of another like below:
class A { }
class B extends A {
1. A x = new B(); // x is a *reference variable* of class A and it points to( refer to) an *object* of class B
2. B x = new A(); // x is a *reference variable* of class B and it points to( refer to) an *object* of class A
} The first one is correct one but the second. I do not have a good explanation for that. The only thing I just know is just because B extends A. Im not convinced myself. Pls help, thanksB extends A means that every B is-an A. That's part of what inheritance means. The main part, IMHO. When you do new B(), you are creating a B object. That B is also an A. Therefore, it is legal to refer to it with a reference variable of type A.
A a; // this says that variable "a" must point to an A object.
a = new B(); // this is legal because every B is an A, so, by pointing to a B object, it is in fact pointing to an AHowever, not all A objects are also B objects
B b; // this says that varaible "b" must point to a B object
b = new A(); // That A is NOT a B object.If you say "hand me a fruit", and someone hands you a pear, and apple, or a banana, he has handed you a fruit.
But if you say "hand me a banana", not just any fruit will do.
Edited by: jverd on Oct 26, 2010 9:55 AM -
"Reset" declared variables to initialized state?
Hiya!
This might sound like a very stupid question, but I have not figured out a way to do this. I am working on a "personal information manager", where users can enter a date in a lovely swing textfield, it get's parsed to Integer and a GregorianCalendar is created with it. Once I created the Calendar, the TextFields are emptied again, but of course the Integer instance variables are still declared with the old values. This leads to the fact that a user could click "add date" again and a date is created without entering any number at all.
My question:
Is it possible to set declared variables back to the state they had when initialized? They should be "empty"...
I can`t set them null...
Thanks for your help, it's much appreciated!The only type of variable where "empty" has any meaning is for an empty string: "". Otherwise there is no empty. Objects are by default initialized to null, numeric primitives to zero, and I think chars to '' but I could be mistaken about that one - I never use chars. So if you're using Integers, they could either be null, or an Integer - nothing else.
-
Varray of Objects: Initializing, Instantiation, Constructors, ORA-06531
This is supposed to fill a varray with ten objects, calling methods in those objects and populating the objects from queries, then display fields from the objects via methods. Error message is in comment at bottom. Any ideas?
-- Enable screen I/O
SET SERVEROUTPUT ON SIZE 1000000
SET VERIFY OFF
-- object spec
CREATE OR REPLACE TYPE employee4 AS OBJECT
o_ename CHAR (20 char),
o_empno NUMBER (4),
o_sal NUMBER (10),
o_thisno NUMBER (4),
MEMBER FUNCTION get_o_ename RETURN CHAR, MEMBER PROCEDURE set_o_ename (o_thisno IN number),
MEMBER FUNCTION get_o_empno RETURN NUMBER, MEMBER PROCEDURE set_o_empno (o_thisno IN number),
MEMBER FUNCTION get_o_sal RETURN NUMBER, MEMBER PROCEDURE set_o_sal (o_thisno IN number),
CONSTRUCTOR FUNCTION employee4 (o_ename CHAR,o_empno NUMBER,o_sal NUMBER,o_thisno NUMBER) RETURN SELF AS RESULT
-- object body
CREATE OR REPLACE TYPE BODY employee4 AS
CONSTRUCTOR FUNCTION employee4 (o_ename IN CHAR,
o_empno IN NUMBER,
o_sal IN NUMBER,
o_thisno IN NUMBER)
RETURN SELF AS RESULT IS
BEGIN
SELF.o_ename := o_ename;
SELF.o_empno := o_empno;
SELF.o_sal := o_sal;
SELF.o_thisno := o_thisno;
RETURN;
END;
-- gets
MEMBER FUNCTION get_o_ename RETURN CHAR IS
BEGIN
RETURN self.o_ename;
END;
MEMBER FUNCTION get_o_empno RETURN NUMBER IS
BEGIN
RETURN self.o_empno;
END;
MEMBER FUNCTION get_o_sal RETURN NUMBER IS
BEGIN
RETURN self.o_ename;
END;
-- sets
MEMBER PROCEDURE set_o_ename(o_thisno IN number) IS
BEGIN
SELECT ename INTO SELF.o_ename FROM emp WHERE empno = SELF.o_thisno;
END;
MEMBER PROCEDURE set_o_empno(o_thisno IN number) IS
BEGIN
SELECT empno INTO SELF.o_empno FROM emp WHERE empno = SELF.o_thisno;
END;
MEMBER PROCEDURE set_o_sal(o_thisno IN number) IS
BEGIN
SELECT sal INTO SELF.o_sal FROM emp WHERE empno = SELF.o_thisno;
END;
END;
DECLARE
-- a varray of employees
TYPE emp_varray1 IS VARRAY(10) OF employee4;
varray_of_emps EMP_VARRAY1;
-- List of EMPNO's in order of appearance in EMP table (for cross-referencing, single-line retrieval)
TYPE MYCREF_VARRAY IS VARRAY(10) OF NUMBER(4);
varray_mycref MYCREF_VARRAY := MYCREF_VARRAY(NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
-- make a variable to store one empno
thisno NUMBER(4);
-- make a counter
counter INT;
-- query variables for the set calls
q_ename CHAR(20 CHAR);
q_empno NUMBER(4);
q_sal NUMBER(10);
BEGIN
-- Put the first 10 EMPNO's in my cref array
SELECT empno BULK COLLECT INTO varray_mycref FROM emp WHERE ROWNUM < 11;
-- Use a loop to retrieve the first 10 objects in the "emp" table and put them in the varray of objects
FOR counter IN 1..10 LOOP
thisno := varray_mycref(counter);
varray_of_emps(counter).set_o_ename(thisno);
varray_of_emps(counter).set_o_empno(thisno);
varray_of_emps(counter).set_o_sal(thisno);
END LOOP;
-- Use another loop to display the information in the reverse order.
FOR counter in REVERSE 1..10 LOOP
dbms_output.put_line((varray_of_emps(counter).get_o_ename()) || CHR(9) || (varray_of_emps(counter).get_o_empno()) || CHR(9) || (varray_of_emps(counter).get_o_sal()));
END LOOP;
END;
This results in the following response in SQL*PLUS:
Type created.
Type body created.
DECLARE
ERROR at line 1:
ORA-06531: Reference to uninitialized collection
ORA-06512: at line 33Hi,
From metalink:
Cause: An element or member function of a nested table or varray was
referenced (where an initialized collection is needed) without the
collection having been initialized.
Action: Initialize the collection with an appropriate constructor or
whole-object assignment.
ORA 6531 Reference to uninitialized collection (Doc ID 48912.1) -
Theorical question about declaration/definition in java
Hi, we know the difference between declaration and definition:
-declaration: no memory is allocated.
-definition: memory is allocated.
In C/C++ if we want to define a variable we can make
int x;or
int x = 5; (we assign a value too)
while, if we just want to declare we can make
extern int x;Is there a way in java to simply declare a variable? According to me just arrays can be declared with
String[] arrayString;while istructions like
String myString;are definition as they allocate at least a String reference on the stack...am I wrong?Squall867 wrote:
Hi, we know the difference between declaration and definition:
-declaration: no memory is allocated.
-definition: memory is allocated.That's not the definition I learned, back when dinosaurs roamed the earth, men lived in caves and used pterodactyls for airplanes, and computers were made of rocks.
Is there a way in java to simply declare a variable? According to me just arrays can be declared withThis is a pretty meaningless question.
In Java, whenever you declare/define a variable (there is no distinction), space is allocated for that variable. It's at least 1 byte for a byte or boolean, at least 2 bytes for a char or a short, at least 4 bytes for an int, float, or reference, and at least 8 bytes for a double or long. A given JVM implementation may actually use more bytes for any given type for word-alignment performance optimization.
Is there a way in java to simply declare a variable? According to me just arrays can be declared with
String[] arrayString;
This declares a reference variable of type reference to array of String. It will occupy at least 4 bytes.
while istructions like
String myString;are definition as they allocate at least a String reference on the stack...am I wrong?This declares a reference variable of type reference to String. It will occupy at least 4 bytes.
Note that an array reference variable is no different than any other reference variable.
Also note that for any variable, whether it lives on the stack or on the heap depends only on whether it's a member variable or a local variable. If objects are allowed to be created on the stack in future versions of Java, that distinction will get slightly more complex. -
Question: Referencing a Java Object
I think I'm suffering from an attack of the 'stupids'. I can't figure out how to do this and I'm sure it's something simple. Any help would be appreciated. I'm simplifying this and I hope I don't mess it up as a result.
I have 4 classes, each written by a different programmer (so no one knows what another person called something). These classes are: MyFrame (extends JFrame), MyData (a data storage object that contains the method 'setData1 (int x)'), MyPanel1 (extends JPanel), and MyPanel2 (extends JPanel).
When the program is run, MyFrame makes 2 objects: Data1 (from MyData) and Panel1 (from MyPanel). In its constructor, MyPanel makes object Panel2 (from MyPanel2).
Now... the question. At some point, Panel2 wants to write something to Data1. What is the proper syntax and/or mechanisms to do this? Remember, in this example, the MyData object is named Data1, but in 'reality' the object can be called anything the programmer wants
I hope this makes sense.
Thanks
MistWing SilverTailYou'll need to pass references around (usually in the constructors), but since you (I'm assuming) can't change/rewrite the classes.... I don't think it could be done.
Even if MyData was declared public, Panel2 can't see MyFrame.
Good luck,
Radish21 -
Questions on ADF View Objects, Links and Iterators
I have a number of questions regarding using ViewObjects in applications where there are alot of relationships between tables.
First, lets say that I have ViewObject SomeView that was added to the App Module (AM) as VO1. And because it has a number of "detail" records that have to be iterated through in a "report like" view it has those other VO's added under it as "children" in the AM.
So I have
VO1 (an instance of SomeView)
--> VO2 (an instance of some other view)
--> VO3 (an instance of some other view)
that is used on pages where only a single VO1 is shown at a time.
Now because I had another page I wanted to make that had a listing of all SomeView objects. Some of the fields in SomeView are foreign keys to records in VO2 and VO3 and while I don't want to show all the fields from VO2 and VO3, I do want to show a name field from each rather than just the foreign key.
My experience (though I've never read this anywhere) tells me that when doing a "table" that is a list of rows from a VO, you can't display info from the child VO's because the child VO's are on whatever record corresponds to the "currentRow" in the parent VO and just displaying the rows in a rangeSet doesn't make each the "currentRow" so even we display 10 records in a for loop, the "currentRow" is just one, and the child VO's iterators aren't moved as we go through the for loop. (Can someone confirm if I am correct on this conclusion????)
So the only way I know of to show some field from a related table in each row is to make the VO have the entity objects from the related tables be part of the view as references. Is this the only way?
If I do that on a view that didn't have other views as children defined in the AM I don't have any problem and it works like I want.
But if I do it on a view that did have other views as children defined in the AM it makes the page(s) using that view with the children iterators behave badly. Half the information quits showing up, etc.
For example, ... if I go to the "SomeView" which was defined with only one entity object association, and I add the entity objects (that are the basis of instances of VO2 and VO3 ) as referenceable only, it totally breaks the page where I display a single VO1 and use it's VO2 and VO3 children. IS THIS NORMAL OR AM I MISSING SOMETHING?
So, is the solution that I have to have more view objects defined for different purposes ?
Can anyone give any general guidelines for when/where to use different view objects vs. when to use different iterators. I'm not having much luck with using secondary RSI's and haven't found much info on them.
Also, how about issues of naming iterators that are in various binding containers (ie. UI Model for a page). If I do and LOV it creates an iterator and gives it a default name like ViewNameIterator1. If I already have a different page that uses a regular (non LOV) iterator with that name, and the user goes back and forth between those pages, is that a clash?
Finally, I've read a couple of Steve Muench's blogs on View Link consistency but I'm not sure what the rules are on when it applies and doesn't. How you turn it on or off, etc. One of his examples in http://radio.weblogs.com/0118231/2004/02/27.html talks about it in the context of two view objects that are NOT typically "linked" in a master/detail kind of way. Like an AllDepartments and a DepartmentsLessThan view. Do you have to create a View Link between them to have results of one be reflected in the other if they aren't used in the same page in a web app? Or does it happen automatically (with the caveat that you have to do the rowQualifies method). Just feels like I'm missing some pieces.
Thanks in advance,
LynnHi,
I am also interested in a best-practice note from oracle.
Currently we store history in seperate history tables for columns that changed. All this implemented in our BaseEoImpl overriding the EntityImpl.prepareForDML().
Thanks -
Question on Using Persistence Object
Hi,
I want to store a hashtable of persistent info with about five attributes (id, name, username, date) in order to not always call the database. I am either going to use session or request objects.
My question is if it's a good idea to store the hashtable with 2000 records just to avoid the database connection or should I just stick with using database connection using connection pooling? Thanks.
MkieHow long you are going to store it ????
1. If it is for a long time then this is not a good strategy as:
a) Database data can change (in that case you will have wrong data)
b) Your heap memory will be unnecessarily loaded.
2. If it is for a very short time then it again carries no meaning as creating the object will have a significant overhead.
3) If it is something between these two. You need to have a thorough analysis to see which would be best. However in my humble opinion a scrollable resultset(JDBC 2.0) will still be better.
Shubhrajit
Maybe you are looking for
-
Disappearing Sticky Note Comments in Acrobat 9 PDF Reviews
I'm using Acrobat 9 Pro (version 9.3.2) and the reviewers are using Reader 9, and all of us are on Windows XP SP3. I'm distributing PDFs for online review using a SharePoint site (SharePoint Server 2007). We've observed the following behaviour if you
-
How to bind a VO :variable in a WHERE clause to a page parameter
Hello, I have a VO. This VO has a variable :v in the WHERE clause of the query. This VO is used by different UI components in a page (a table, a tree). The page already has a parameter defined in his properties #{viewScope.myparam} What I want is to
-
Opening attached .pdf and .doc files
I am having a mental moment and can't figure out how to (attach to button) import .pdf or .doc files so that they open when the project is published. The buttons are linked to files on my computer...when I publish, Captivate knows the files are there
-
How do I move/export a letterhead I created on Photoshop to MS Word (Mac)?
I can get it there but I can't type on it. I'm pretty sure I've done this in the past but I can't remember how.
-
PowerBook continuously reboots after running Software Update
This morning I ran Software Update on my Powerbook. There were about 5-6 items including the latest Mac OS X update, Java, iTunes and a couple other things. The update scripts ran without incident. However, when it tries to restart, it keeps rebootin