_root variable in class
i want to pass _root variables to a component
how can i do that ?
this is a partial script from the component:
Not familiar with global variable.
Is the JDialog part of your package or a subclass of the applet?
If the panel is a subclass you can access it the follwing way:
public class app extends Applet{
String sourcePath = "";
class Sub(){
app.this.sourcePath = "...";
// or
String myVar = app.this.sourcePath;
}If the JDialog is part of a package It depends if your
applet exposes it .
Package String myVar = "";
From the applet pass a reference to the JDialog:
new myJDialog(this);
and in the myJDialog add a constructor that holds the reference to the applet
class myJDialog extends JDialog{
private myApplet a
public myJDialog(myApplet app){
this.a = app;
// anywhere in code:
this.a.myVar = "";
//or
myJDialogVar = this.a.myVar;
}
Similar Messages
-
How share variables between classes ???
Hi !
Basically I have two classes and I would like them to share a variable, I mean, when I modify it on one class the other one is also affected.
how can I do that ? by using the inheritance principle or is it a simple way so that we don't have one more class??
thank you a lot for your answer !
PAIf you want them to always have the same value, you should have only one variable:public class ClassOne
private static int theVar = 0;
public static void setTheVar(int value){theVar = value;}
public static int getTheVar(){return theVar;}
public class ClassTwo
public static int getTheVar(){return ClassOne.getTheVar();}
} -
Undefined variable or class name
I am trying to call a java class to another class but gets the error: "Undefined variable or class name"
Both my java files are in the same directory and I am able to compile only one of the program. Wondering what am I missing?
The source code is:
ServletUtilities.java: (I am able to compile)
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ServletUtilities {
public static final String DOCTYPE =
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
"Transitional//EN\">";
public static String headWithTitle(String title) {
return(DOCTYPE + "\n" +
"<HTML>\n" +
"<head><title>" + title + "</title></head>\n");
HelloWWW3.java (getting error when compile)
public class HelloWWW3 extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println(ServletUtilities.headWithTitle("Hello WWW") +
"<body>\n" +
"<h1>Hello WWW</h1>\n" +
"</body></html>");I tried and I got these errors:
C:\java servlets\HelloWWW3\src>javac -classpath . HelloWWW3.java
HelloWWW3.java:4: Package javax.servlet not found in import.
import javax.servlet.*;
^
HelloWWW3.java:5: Package javax.servlet.http not found in import.
import javax.servlet.http.*;
^
HelloWWW3.java:7: Superclass coreservlets.HttpServlet of class coreservlets.Hell
oWWW3 not found.
public class HelloWWW3 extends HttpServlet
^
3 errors
Then I moved HelloWWW3.java and ServletUtilities.class file to C:\jakarta-tomcat-3.2.3\lib
This dir has files
JAXP JAR
SERVLET JAR
ANT JAR
PARSER JAR
WEBSER~1 JAR
JASPER JAR
and compiled and got this error
C:\jakarta-tomcat-3.2.3\lib>javac -classpath . HelloWWW3.java
HelloWWW3.java:4: Package javax.servlet not found in import.
import javax.servlet.*;
^
HelloWWW3.java:5: Package javax.servlet.http not found in import.
import javax.servlet.http.*;
^
HelloWWW3.java:7: Superclass coreservlets.HttpServlet of class coreservlets.Hell
oWWW3 not found.
public class HelloWWW3 extends HttpServlet
^
3 errors
Here is what I hava defined for my CLASSPATH
C:\jakarta-tomcat-3.2.3\lib>echo %CLASSPATH%
C:\jakarta-tomcat-3.2.3\lib\servlet.jar;C:\jakarta-tomcat-3.2.3\lib\jasper.jar
------------------------------------------ -
Flatten to XML bug with unit variables in classes
Hi,
I just spent about 5 hours trying to figure out why some of my class data kept resetting itself to zero. Turns out that the part that kept resetting was the part that had a unit variable in it, and that fails to load properly from the Unflatten From XML VI. It works fine if it's just a cluster, it's being in a class that's the problem.
I've attached the zip file with the example VIs.
Could I ask that someone with LV 2014 try this to see if the bug exists there?
Right now we're running 2011, but we plan a companywide shift to 2015 as soon as it comes out (and therefore, 2011 drops from extended support). I'd like to know if I can just wait for the upgrade and then it will work, or if I need to redo about ~15 variables in classes with units on them that I had been counting on loading and saving using the built-in XML functions.I was planning on trying for a CAR only after confirming the problem hadn't been quietly fixed in the last 3 years. I couldn't find anything in the changelogs but sometimes you never know...
Now that UliB has confirmed it's still a problem I will likely do so. -
Problem with variable in class file.
Im working on a project from school where I read in a text file with numbers and print the max and the min. In my main file, I read in the text file and set the different numbers to variables a, b, and c. My question is, when Im writing my class file MaxMin, is there anyway to access those variables to compare them? Or will I have to do it some other way. Thanks for your help.
Ok. Sorry
Here is the main code
import java.io.*;
import java.util.StringTokenizer;
public class LabAssign1
public static void main(String[] args) throws IOException
final int TOKENS_PER_LINE = 3;
String fileName = "labassign1.txt";
File theFile = new File(fileName);
FileInputStream theStream = new FileInputStream(theFile);
InputStreamReader theReader = new InputStreamReader(theStream);
BufferedReader input = new BufferedReader(theReader);
int numLines = 0;
String line = input.readLine();
while (line != null)
StringTokenizer st = new StringTokenizer(line);
if (line.length() == 3)
int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());
int c = Integer.parseInt(st.nextToken());
else
line = input.readLine();
input.close();
Is there any way to call variables a,b,and c in a separate class file? -
What is the difference between instance variable and class variable?
i've looked it up on a few pages and i'm still struggling a bit maybe one of you guys could "dumb" it down for me or give and example of how their uses differ.
thanks a lotInstance is variable, class is an object.What? "Instance" doesn't necessarily refer to variables, and although it's true that instances of Class are objects, it's not clear if that's what you meant, or how it's relevant.
if you declare one instance in a class that instance
should be sharing within that class only.Sharing with what? Non-static fields are not shared at all. Sharing which instance? What are you talking about?
if you declare one class object it will share
anywhere in the current program.Err...you can create global variables in Java, more or less, by making them static fields. If that's what you meant. It's not a very good practice though.
Static fields, methods, and classes are not necessarily object types. One can have a static primitive field. -
An object variable and class name
How come some classes, such as wrapper classes, don?t use an object variable to call a method in their classes? For example, StingBuffer or String class needs an object variable to call its method but Double, Integer, Character, NumberFormat, or some other classes doesn?t use an object variable to call a method in its class. Why is that? Any suggestions? Any explanation would be helpful.
errr.. do you mean static methods and instance methods?
http://java.sun.com/docs/books/tutorial/java/javaOO/classvars.html -
How can i pass variables between classes?
Hi.
i have three classes and i need use a variable from 'Battleship' and use it in 'BattleWindow', these summaries of the classes, if anyone could give me a solution without editing it too much it would be greatly appreciated
public class Ship{
public Ship(){
int missilesLeft;
int shots = 10;
for (int i=0;i<8;i++) {
missilesLeft = shots - 1;
//Panel
public class PanelWindow{
public static void main (String [] args) {
System.out.println(missilesLeft.Ship);
Andrewi still can get it to work.. but i think that you got me quite close;
this is where i need to get missilesLeft from
//BattleShip
public void mouseClicked(MouseEvent e){
tries--;
for (int i = 0; i < 8; i++){
for (int j = 0; j < 8; j++){
if (e.getSource().equals(buttons[i][j]) && ship[i][j] == true){
buttons[i][j].setBackground(new Color(80,80,80));
hit++;
System.out.println(hit+" "+total);
else if (e.getSource().equals(buttons[i][j]) && ship[i][j] == false){
buttons[i][j].setBackground(new Color(0,0,255));
//Win
if (isWin()){
int hits = 64 - tries;
int misses = hits- hit;
int score = ((tries+hit)/misses)*64;
missilesLeft = tries - 30;
mis = missilesLeft;
JOptionPane.showMessageDialog(this, "You WIN!\n \nMissiles used: "+hits+"\nMissiles left: "+missilesLeft+"\nHits: "+hit+"\nMisses: "+misses+"\nScore: "+score );
//Game Over
if (isGameOver()){
JOptionPane.showMessageDialog(this, " GAME OVER!!\n*******************\nYou have run out of missiles!\nTRY AGAIN");
//BattleWindow
private void build(){
main = new JPanel(new BorderLayout());
title = new JPanel(new FlowLayout(FlowLayout.CENTER));
right= new JPanel(new FlowLayout(FlowLayout.CENTER));
left = new JPanel(new FlowLayout(FlowLayout.CENTER));
bottom = new JPanel(new FlowLayout(FlowLayout.RIGHT));
displayField = new JTextField("000", 8);
displayField.setEditable( false );
b = new Battleship();
JLabel t = new JLabel("Battleship Potemkin");
Font myFont = new Font("Arial",Font.BOLD,32);
t.setFont(myFont);
title.add(t);
help = new JButton("Help");
exit = new JButton("Quit");
help.setFont(new Font("Arial", Font.BOLD, 17));
exit.setFont(new Font("Arial", Font.BOLD, 17));
displayField.setFont(new Font("Arial", Font.BOLD, 22));
main.add(title,BorderLayout.NORTH);
main.add(left,BorderLayout.WEST);
main.add(right,BorderLayout.EAST);
main.add(bottom,BorderLayout.SOUTH);
main.add(b,BorderLayout.CENTER);
this.add(main);
help.addMouseListener(this);
exit.addMouseListener(this);
bottom.add(displayField);
bottom.add(help);
bottom.add(exit);
setSize(500,600);
setResizable(false);
String aString = Integer.toString(bob);
displayField.setText(displayField.getText() + bob);
//displayField.setText("bob");
}the variable bob in must have the same value as missilesLeft
thank you -
Hi friends,
1.can you tell me the Disadvantages of Shared Variables?
2.What is classes ,how to make it?
RajHi! Raj
Shared Variables
shared variables share data between loops on a single diagram or between VIs across the network. For doing that they break the LabVIEW dataflow paradigm.
Disadvantages:
1. Using variables allows for race conditions and incurs more overhead than passing the data by wire(break the LabVIEW dataflow paradigm).
Race conditions happen when you, for example, write data to a shared resource from multiple operations faster than you read data from the same shared resource.
2.You must have a project open to create a shared variable
You can also read more about shared variables at http://zone.ni.com/devzone/cda/tut/p/id/4679
Attachments:
Race condition.PNG 57 KB -
Accessing _root variable from flex
In Flex code, I am trying to access a variable that I pass to
the Flash object through FlashVars argument. In Flash it is easy to
do as all the variables that as passed as a part of FlashVars
appear as a part of _level0 or _root. Is there any way to do it in
Flex?
I am trying pass a large dataset directly to Flash without an
http call (creating a desktop application). Does anyone know if the
FlashVars approach will work for a large dataset or is there a
better approach?
ThanksFrom the Flex 2.0.1 help (search for Using flashVars):
The following example sets the values of the firstname,
middlename, and lastname flashVars properties inside the
<object> tag in a simple wrapper:
<?xml version="1.0"?>
<!-- wrapper/ApplicationParameters.mxml -->
<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"
creationComplete="initVars()">
<mx:Script><![CDATA[
// Declare bindable properties in Application scope.
[Bindable]
public var myName:String;
[Bindable]
public var myHometown:String;
// Assign values to new properties.
private function initVars():void {
myName = Application.application.parameters.myName;
myHometown = Application.application.parameters.myHometown;
]]></mx:Script>
<mx:VBox>
<mx:HBox>
<mx:Label text="Name: "/>
<mx:Label text="{myName}" fontWeight="bold"/>
</mx:HBox>
<mx:HBox>
<mx:Label text="Hometown: "/>
<mx:Label text="{myHometown}" fontWeight="bold"/>
</mx:HBox>
</mx:VBox>
</mx:Application>
If you are using the wrapper that is generated by Flex Data
Services or wrappers that are included in the
resources/html-templates directory, your wrapper might not look the
same, but the basic approach to passing the flashVars variable is.
For example, you might insert flashVars variables by appending them
to a function parameter, as the following example shows:
"flashvars","historyUrl=%2Fflex%2Fflex%2Dinternal%3Faction%3Dhistory%5Fhtml&lconid="
+ lc_id + "&firstName=Nick&lastName=Danger", -
Passing an variable through classes on init
i have a main class
this class starts up another class
so iv got 3 classes
class1
-load class2
class2
-load class3
class3
maxslots = 0
now that maxslots variable i want to set up from the VERY first class1
but i cant see how you pass it thought the classes so its loaded when each class is started up
class class1{
private static class2 class2x= null;
public static void main(String[] args) throws IOException {
class2x= new class2(7);
}ok so my class 2 now has 7
public class class2 implements Runnable {
int maxSlots = 0;
static class3 class3x= new class3(maxSlots);
public class2(int maxSlotsx) {
maxSlots = maxSlotsx
public class class3{
int maxSlots = 0;
public class3(int maxSlotsx) {
maxSlots = maxSlotsx
System.out.println("maxSlots"+maxSlots);
}now in class 2 i CANT place the set up class3 thing within class2 constructor because its runnable and only want it done ONCE
any idea how to pass var 7 down to my end class3
thanks :)ah i worked it out lol
-
Help: I am trying to pass a variable between classes
I am trying to pass data in a variable inbetween two classes is there any suggestions as to how to do this? Here is a example of the code I am trying to pass MqMessage to the class MqLog.
if(MqMessage.equals("END"))
finalize();
System.exit( 0 );
else //else build flat file and launch docusolve
MqLog tempMqLog = new MqLog();
tempMqLog.levelThreeDiagnostic();
aRuntime = null;
aProcess = null;
}I don't really undestand what you are asking specifically. If you only want to transfer a value from one Object to another Object, then you should just use a set method:
if (objectOne.getValue().equals("END"))
end();
else
objectTwo.setValue(objectOne.getValue()) -
Accessing a public variable between classes
Hi there,
I've got two classes running...one is a document class (EgoGame.as) and another is a class linked to several similar movie clips (Ball.as).
I'm trying to access a public variable from Ball.as which has been declared in the doucment class EgoGame.as.
When I run the test the outputs states the following...
1120: Access of undefined property _ballPlaced.
Here's my code. What I'm trying to do is remove the event listeners from the Ball.as when the _ballPlaced variable is true, so that the user can't drag and drop the balls after they've been placed in a zone....any pointers greatly appreciated!
Document Class
EgoGame.as
package
import flash.display.MovieClip;
import flash.display.DisplayObject;
import flash.events.MouseEvent;
import Ball;
public class EgoGame extends MovieClip
public var __zoneFull:Array = new Array(false, false, false);
public var __ballPlaced:Array = new Array(false, false, false);
public function EgoGame()
ball0_mc.addEventListener(MouseEvent.MOUSE_DOWN, zoneEmpty);
ball1_mc.addEventListener(MouseEvent.MOUSE_DOWN, zoneEmpty);
ball2_mc.addEventListener(MouseEvent.MOUSE_DOWN, zoneEmpty);
ball0_mc.addEventListener(MouseEvent.MOUSE_UP, zoneFill);
ball2_mc.addEventListener(MouseEvent.MOUSE_UP, zoneFill);
ball1_mc.addEventListener(MouseEvent.MOUSE_UP, zoneFill);
ball0_mc.addEventListener(MouseEvent.MOUSE_UP, playMovie);
ball1_mc.addEventListener(MouseEvent.MOUSE_UP, playMovie);
ball2_mc.addEventListener(MouseEvent.MOUSE_UP, playMovie);
private function zoneEmpty(event:MouseEvent):void
if(event.target.hitTestObject(zone0_mc) && _zoneFull[0] == true)
_zoneFull[0] = false;
_ballPlaced[event.target.name.substring(4,5)] = false;
else if(event.target.hitTestObject(zone1_mc) && _zoneFull[1] == true)
_zoneFull[1] = false;
_ballPlaced[event.target.name.substring(4,5)] = false;
else if(event.target.hitTestObject(zone2_mc) && _zoneFull[2] == true)
_zoneFull[2] = false;
_ballPlaced[event.target.name.substring(4,5)] = false;
else
event.target.x = event.target._startX;
event.target.y = event.target._startY;
_ballPlaced[event.target.name.substring(4,5)] = false;
private function zoneFill(event:MouseEvent):void
if(event.target.hitTestObject(zone0_mc) && _zoneFull[0] == false)
event.target.x = zone0_mc.x;
event.target.y = zone0_mc.y;
_zoneFull[0] = true;
_ballPlaced[event.target.name.substring(4,5)] = true;
else if(event.target.hitTestObject(zone1_mc) && _zoneFull[1] == false)
event.target.x = zone1_mc.x;
event.target.y = zone1_mc.y;
_zoneFull[1] = true;
_ballPlaced[event.target.name.substring(4,5)] = true;
else if(event.target.hitTestObject(zone2_mc) && _zoneFull[2] == false)
event.target.x = zone2_mc.x;
event.target.y = zone2_mc.y;
_zoneFull[2] = true;
_ballPlaced[event.target.name.substring(4,5)] = true;
else
event.target.x = event.target._startX;
event.target.y = event.target._startY;
_ballPlaced[event.target.name.substring(4,5)] =false;
private function playMovie(event:MouseEvent):void
if (_ballPlaced[0] == true)
ball0_mc.gotoAndPlay(2);
else
ball0_mc.gotoAndStop(1);
if (_ballPlaced[1] == true)
ball1_mc.gotoAndPlay(2);
else
ball1_mc.gotoAndStop(1);
if (_ballPlaced[2] == true)
ball2_mc.gotoAndPlay(2);
else
ball2_mc.gotoAndStop(1);
Ball.as
package
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.display.DisplayObject;
import EgoGame;
public class Ball extends MovieClip
// public var _hitTarget:MovieClip;
public var _startX:Number;
public var _startY:Number;
public function Ball()
_startX = this.x;
_startY = this.y;
this.buttonMode = true;
this.addEventListener(MouseEvent.MOUSE_DOWN, dragIt);
this.addEventListener(MouseEvent.MOUSE_UP, dropIt);
private function dragIt(event:MouseEvent):void
this.startDrag();
public function dropIt(event:MouseEvent):void
this.stopDrag();
public function lockBall(event:MouseEvent):void
if(_ballPlaced[this.name.substring(4,5)] == true)
this.removeEventListener(MouseEvent.MOUSE_DOWN, dragIt);
this.removeEventListener(MouseEvent.MOUSE_UP, dropIt);every place you have a ball reference you can access the lockBall() method. so, if ball0_mc is a Ball class member, you can use:
ball0_mc.lockBall(); -
Newbie: Return variable from class?
I'm calling a class to verify some data. The verification is quite complicated so the class will use a JFrame to make things clearer and will popup some additional dialogs. What I can't work out is the syntax for returning a variable from the class.
I'm using the constructor to build and show the JFrame with the data to be verified and then triggering off a JButton to start the verification. If all is OK then the class would return a result.
What I would like is to call either the Constructor or a Method in the class to show the JFrame, and to get that to return a value to me when a JButton is clicked. Does anyone have any code samples of something like this, or could point me in the right direction? It feels messed up right now.The simplest way is to use JDialog with setModal(true). Write your subclass of it and include a result field, typically a boolean that determines whether you exited via "OK" or "Cancel". The handlers for the buttons set this field appropriately, then you do "show" on the dialog (which waits until one of the button handlers calls "dispose" on the dialog), then test the flag.
public class MyDialog extends JDialog {
boolean resultOk;
JButton okButton, cancelButton;
public MyDialog(Frame parent) {
super(parent, "Validate dialog", true);
okButton = new JButton("OK");
okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if(formIsValid()) {
resultOk = true;
dispose();
cancelButton = new JButton("Cancel");
cancelButton.addActionListner(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
resultOK = false;
dispose();
private boolean formIsValid() {
.... validation
MyDialog dlg = new MyDialog(parentFrame);
dlg.show();
if(dlg.resultOK) { // ok button selected
... -
I have an application with a sizeable number, about 70, variables declared at the class level. The scope for those variables therefore applies to all of the class's methods and sub classes. The reason for doing like that is that those variables are used many times in many methods. Many of the variables could be passed as parameters to the methods but in this case it would cause a large number of parameter passing, whereas using the �global� nature of the variables as they are seems to be more workable approach for the application. Apart from making the methods not re-useable, are there any other implications in terms of performance or otherwise of taking such an approach. I just feel that I am violating some conventions or standard practice by doing so.
ChrisHow can I wrap many parameters, that may be a variety
of primatives and arrays etc., in a second object?You could use a class, a Map or an array/varags. Depend on what you need.
You are bound to question the array, so you can (I am NOT recomending this however) pass an array of refs, containing a array of each primitive type.
new Object[] { new int[] { 1 }, new double[] { 2.1 } };Personally I think 70 members is a lot. Are you sure your object is not attempting to do too much?
Maybe you are looking for
-
Subtitle support needed for apple tv
i am hearing impaired and was frustrated to download a movie and found no support for subtitles. Please apple fix this problem.
-
Transferring audiobook from Macbook Pro to iMac
I bought an audiobook today on my Macbook Pro, forgetting that my iPhone is syncing with my iMac. In the past I have been able to use home sharing to move songs and books from one to the other. I can't do that today. Anyone know why? I am suspect
-
I have a program that creates and starts Threads that invokes a webservice..I just want to know if incase one Thread had an exception will it effect the processing of other threads, or it will effect the execution of the program? here is my code (par
-
Getting "IPEnqueueError end" while using ReSubmit utility
Hi Gurus, When I tried to to resubmit the failed message using resubmit utility, I am getting "IPEnqueueError end" as output. I have pasted the output of this test. I am using file system. Please suggest. D:\OracleB2B-Installation\OraHome_Cache\ip\in
-
How can we create web shop in sap crm 4.0 version
hi, crm gurus, plz anser my question. thanks in advance