Variable port in Socket class
How does the variable "port" in the socket class point to the Network interface?
How does the variable "port" in the socket class when
given a value point to the specified port?I don't understand this at all, sorry.
Also is there any way a port can be binded to and
controlled when in use by an application like
NetBios? ie opening or closing therby stopping the
applications usage over a LAN.If a port number is already in use you can't do anything with it except try to connect to it.
May I suggest Stevens TCP/IP Illustrated volume I.
Similar Messages
-
The connect function in the socket class has problems
when i call this function connect(SocketAddress endpoint, int timeout)
the timeout variable doesnt wait for the specific time that i tell it
example
connect(endpoint, 10000);
this call should wait for this amount of time but it doesnt wait that amount
any body has a answer ???yes that is exactly what I am saying
I specify 10 sec, as 10000 milli sec's in the connect function but I get an exception almost imediately when i run my java program...
run this code
import java.net.*;
public class Test
public static void main(String [] args)
{ Socket s = null;
int port = 2000;
try
s = new Socket();
InetSocketAddress i = new InetSocketAddress("localhost",port);
//this next line should wait 10 sec's then throw and exception
//but it throws and exception upon running the this code
s.connect(i,10000);
catch(Exception e){ System.out.println(e.toString()); }
}//main
}//Test
I have also tried setting the setSoTimeout(10000) in the Socket class but
still with no success...
I dont know why this doesnt wait 10 sec's then through an exception on it
and when i try it with a java server it connects instantly...
any help anyone??? -
Binding a JavaFX variable to a Java class instance variable
Hi,
I am pretty new to JavaFX but have been developing in Java for many years. I am trying to develop a JavaFX webservice client. What I am doing is creating a basic scene that displays the data values that I am polling with a Java class that extends Thread. The Java class is reading temperature and voltage from a remote server and storing the response in an instance variable. I would like to bind a JavaFx variable to the Java class instance variable so that I can display the values whenever they change.
var conn: WebserviceConnection; // Java class that extends Thread
var response: WebserviceResponse;
try {
conn = new WebserviceConnection("some_url");
conn.start();
Thread.sleep(10000);
} catch (e:Exception) {
e.printStackTrace();
def bindTemp = bind conn.getResponse().getTemperature();
def bindVolt = bind conn.getResponse().getVoltage();
The WebserviceConnection class is opening a socket connection and reading some data in a separate thread. A regular socket connection is used because the server is not using HTTP.
When I run the application, the bindTemp and bindVolt are not updated whenever new data values are received.
Am I missing something with how bind works? Can I do what I want to do with 'bind'. I basically want to run a separate thread to retrieve data and want my UI to be updated when the data changes.
Is there a better way to do this than the way I am trying to do it?
Thanks for any help in advance.
-RichardHi,
If you don't want to constantly poll for value change, you can use the observer design pattern, but you need to modify the classes that serve the values to javafx.
Heres a simple example:
The Thread which updates a value in every second:
// TimeServer.java
public class TimeServer extends Thread {
private boolean interrupted = false;
public ValueObject valueObject = new ValueObject();
@Override
public void run() {
while (!interrupted) {
try {
valueObject.setValue(Long.toString(System.currentTimeMillis()));
sleep(1000);
} catch (InterruptedException ex) {
interrupted = true;
}The ValueObject class which contains the values we want to bind in javafx:
// ValueObject.java
import java.util.Observable;
public class ValueObject extends Observable {
private String value;
public String getValue() {
return this.value;
public void setValue(String value) {
this.value = value;
fireNotify();
private void fireNotify() {
setChanged();
notifyObservers();
}We also need an adapter class in JFX so we can use bind:
// ValueObjectAdapter.fx
import java.util.Observer;
import java.util.Observable;
public class ValueObjectAdapter extends Observer {
public-read var value : String;
public var valueObject : ValueObject
on replace { valueObject.addObserver(this)}
override function update(observable: Observable, arg: Object) {
// We need to run every code in the JFX EDT
// do not change if the update method can be called outside the Event Dispatch Thread!
FX.deferAction(
function(): Void {
value = valueObject.getValue();
}And finally the main JFX code which displays the canging value:
// Main.fx
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.text.Text;
import javafx.scene.text.Font;
import threadbindfx.TimeServer;
var timeServer : TimeServer;
var valueObjectAdapter : ValueObjectAdapter = new ValueObjectAdapter();
timeServer = new TimeServer();
valueObjectAdapter.valueObject = timeServer.valueObject;
timeServer.start();
Stage {
title: "Time Application"
width: 250
height: 80
scene: Scene {
content: Text {
font : Font {
size : 24
x : 10, y : 30
content: bind valueObjectAdapter.value;
}This approach uses less cpu time than constant polling, and changes aren't dependent on the polling interval.
However this cannot be applied to code which you cannot change obviously.
I hope this helps. -
Hod do I pass a socket variable over a socket connection
Anyone know what syntax I could use to pass a socket variable over a socket connection? I can't imagine it'll go as a string, int, or double. --That's all I know how to pass.
I was trying to get two programs accesing a server
program through the same socket connection. Are you
telling me this is impossible? If so, please go to
this link and give me a hand with the other way I
think I can get this to work...Sure ya can....
...something like this:
Server:
ServerSocket serverSock = new ServerSocket(8888); // 8888 = whatever port you want to listen on
while (bWaitingConnections)
Socket socket = serverSock.accept(); // WAIT until client connects to our port.
Thread thread = new MySocketHandlingThread(socket);
thread.start();
}Client:
Socket socket = new Socket(sServerHostName, 8888);
// ... connected to Server on port 8888 .... -
Stupid question - method missing from Socket class
I'm sure I am just missing something here. I am using getInputStream from Socket class successfully - now want to add setKeepAlive method - I am getting an error:
Method setKeepAlive(boolean) not found in class java.net.Socket.
client.setKeepAlive(true);
client is defined as a Socket
Socket client = origSocket.accept();
What am I screwing up here?? I know the classpath is correct since I am and have been using getInputStream with this socket for months!!
Thanks for any responses!
Bethjavac is the compiler, not the run-time. That would have nothing to do with what the classpath is at run-time, which would either be the system environment variable CLASSPATH, or the -cp command-line parameter to java, not javac.
-
Listening socket class freezes my program
i originaly created a listening socket in my main gui class but everytime i execute it, my gui appears with no visible components inside and freezes. i am not able to close the gui window by clicking on the x button at teh top right hand corner.
i then removed my listening socket and made a new class altogether that listens to socket connection. i get the same problem when i execute both my gui and listening socket class. any suggestions?
heres my socket listening class
package icomm;
import java.net.*;
import java.io.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class listening {
/** Creates a new instance of listening */
public listening() {
public void listeningSocket()
ServerSocket server = null;
boolean listening = true;
try
//listen in port 4444;
server = new ServerSocket(14);
catch(IOException x)
JOptionPane.showMessageDialog(null, "cannot listen to port 4444", null, JOptionPane.ERROR_MESSAGE);
while(true)
ChatDialog w;
try
w = new ChatDialog(server.accept());
Thread t = new Thread(w);
w.setVisible(true);
t.start();
// server.close();
catch(IOException x)
JOptionPane.showMessageDialog(null, "could not open chat window", null, JOptionPane.ERROR_MESSAGE);
}and here is the code that launches the gui and the listening class from my login button..
//laod main gui
show_main_gui(text_username.getText());
//run listening socket
listening listen = new listening();
listen.listeningSocket();you do not need any thread for this - the socket will not block your frame. here is an example which works:
import java.net.ServerSocket;
import javax.swing.JFrame;
public class Sockframe extends JFrame{
public Sockframe(){
super("Socket using Application");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(100,100);
* @param args
public static void main(String[] args) {
// show new Frame
Sockframe f = new Sockframe();
f.setVisible(true);
try{
// do socket stuff
ServerSocket s = new ServerSocket(4567);
s.accept();
} catch(Exception exc){
exc.printStackTrace();
}Did you provide some default close operation for the frame? The frame needs this to know how to behave when the X-button os pressed. -
Extending the Socket class...
I need some help. The class below, SimpleSocket, extends the built-in
Socket class and adds two methods to it. These methods are meant to
make the class a bit more user-frienly but simplifying the reading-from
and writing-to a Socket object. Here it is:
bq. import java.net.*; \\ import java.io.*; \\ public class SimpleSocket extends Socket { \\ BufferedReader in; \\ PrintWriter out; \\ public void println(String line) throws IOException \\ { \\ if (out == null) { out = new PrintWriter(this.getOutputStream(), true); } \\ out.println(line); \\ } \\ public String readLine() throws IOException \\ { \\ if (in == null) { in = new BufferedReader( new InputStreamReader(this.getInputStream())); } \\ return in.readLine(); \\ } \\ }
If I want to create a new SimpleSocket, it's easy - I can instantiate it like a normal Socket:
bq. SimpleSocket socket = new SimpleSocket(host,port); // assume host & port have been defined
Now, lets say I have a Socket object that I didn't created - for
example, a Socket returned from the ServerSocket class - like this:
bq. ServerSocket serverSocket = new ServerSocket(port); \\ Socket clientSocket = serverSocket.accept(); // returns the socket for communicating with a client
Now that I have a regular Socket object, is there some what to
"upgrade" it to a SimpleSocket? Something like this: (pseudocode):
bq. clientSocket.setClass(SimpleSocket); // this is pseudocode
Or, could I make a SimpleSocket constructor that accepted a Socket
object as a parameter and then used it instead of creating a new
object? Like this: (psuedocode):
bq. public SimpleSocket(Socket S) \\ { \\ super = S; // this is pseudocode \\ }
Any ideas would be greatly appreciated.
Lindsay
Edited by: lindsayvine on Sep 15, 2007 10:50 PMlindsayvine wrote:
Ok, this makes sense and this is what I will probably do. However, there are three limitations to this method that I don't like:
1. I would like to be able to pass the SimpleSocket object around as a normal Socket. I would like SimpleSocket to be castable to a Socket.Would you? What for? Are you sure? Would input and output streams not be better objects to pass around? You might well have the requirement you say you have, but I say it's an assumption to be challenged, at the very least
2. I would like every method of the Socket object to be available - this would means that I have to rewrite out every method in SimpleSocket - instead of just saying "hey SimpleSocket, you should have every method Socket has"Yep. But using inheritance simply to avoid some typing is no reason to use inheritance. This is all providing that you need to have every method available. Remember, if any dependent code needs the underlying socket object, your interface can always expose it
3. If I do write out every method, but then the Socket object gets new methods in future versions of Java, I will have to add the new ones.Likewise, in the case of such a change to java.net.Socket, your subclass has a very real chance of breaking. Again, consider if your code needs to exactly replicate everything a Socket does
Can you think of any way around these problems?
Sure. Re-think your design -
How to create one submit form for both input an variable ports ?
Hello,
I would like to create an input from for a query I have.
The problem is that this query has both input an variable ports and each one creates a different input form. I would like to join it into one form or at least have it under one "Submit" button so the user won't need to fill two forms.
How can I achieve this?Hi Mario,
Thank you for your quick reply.
>>Even if you could, only port would be effective.
Can you please elaborate?
>> You need to change your query and make your input port-fields variables?
So, if I understand correctly I should select whether I go for only inputs or only variables?
Thanks,
Roy -
Using Variables/Arrays from one class in another
Hello all,
First, to explain what I am attempting to create, is a program that will accept input of employee names and hours worked into an array. The first class will accept a command line argument when invoked. If the argument is correct, it will call another class that will gather information from the user via an input box. After all names and hours have been input for employees, this class will calculate the salary based upon the first letter of each employee name and print the total hours, salary, etc. for each employee.
What I need to do now is to split the second class into two: one that will gather the data and another that will calculate and print the data. Yes, this is an assignment. However, I am trying to learn and I have gotten this far, but I am stuck on how to get a class to be able to use an array/variables from another class.
I realize the below code isn't exactly cleaned up...yet.
Code for AverageSalaryGather class:
import javax.swing.JOptionPane; // uses class JOptionPane
import java.lang.reflect.Array;
import java.math.*;
public class AverageSalaryGather {
public static void gatherData() {
char[] alphaArray = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','x','y','z'};
String[][] empInfoArray = new String[100][4];
String[] empNameArray = new String[100];
String finalOutput = "Name - Rate - Hours - Total Pay\n";
String averageHoursOutput = "Average Hours Worked:\n";
String averageSalaryOutput = "Average Hourly Salary:\n";
String averageGroupSalaryOutput = "Average Group Salary:\n";
String[] rateArray = new String[26];
char empNameChar = 'a';
int empRate = 0;
int payRate = 0;
for (int i = 0; i < 26; i++) {
payRate = i + 5;
rateArray[i] = Integer.toString(payRate);
int countJoo = 0;
while (true) {
String namePrompt = "Please enter the employee name: ";
String empName = JOptionPane.showInputDialog(namePrompt);
if (empName == null | empName.equals("")) {
break;
else {
empInfoArray[countJoo][0] = empName;
for (int i = 0; i < alphaArray.length; i++) {
empNameChar = empName.toLowerCase().charAt(0);
if (alphaArray[i] == empNameChar) {
empInfoArray[countJoo][1] = rateArray;
break;
countJoo++;
// DecimalFormat dollarFormat = new DecimalFormat("$#0.00");
for (int i = 0; i < empInfoArray.length; i++) {
if (!(empInfoArray[i][0] == null)) {
String hourPrompt = "Please enter hours for " + empInfoArray[i][0] + ": ";
String empHours = JOptionPane.showInputDialog(hourPrompt);
int test = 0;
empInfoArray[i][2] = empHours;
// convert type String to double
//double tmpPayRate = Double.parseDouble(empInfoArray[i][1]);
//double tmpHours = Double.parseDouble(empInfoArray[i][2]);
//double tmpTotalPay = tmpPayRate * tmpHours;
// create via a string in empInfoArray
BigDecimal bdRate = new BigDecimal(empInfoArray[i][1]);
BigDecimal bdHours = new BigDecimal(empInfoArray[i][2]);
BigDecimal bdTotal = bdRate.multiply(bdHours);
bdTotal = bdTotal.setScale(2, RoundingMode.HALF_UP);
String strTotal = bdTotal.toString();
empInfoArray[i][3] = strTotal;
//String strTotalPay = Double.toString(tmpTotalPay);
//empInfoArray[i][3] = dollarFormat.format(tmpTotalPay);
else {
break;
AverageSalaryCalcAndPrint averageSalaryCalcAndPrint = new AverageSalaryCalcAndPrint();
averageSalaryCalcAndprint.calcAndPrint();
Code for AverageSalaryCalcAndPrint class (upon compiling, there are more than a few complie errors, and that is due to me cutting/pasting the code from the other class into the new class and the compiler does not know how to access the array/variables from the gatherData class):
import javax.swing.JOptionPane; // uses class JOptionPane
import java.lang.reflect.Array;
import java.math.*;
public class AverageSalaryCalcAndPrint
public static void calcAndPrint() {
AverageSalaryGather averageSalaryGather = new AverageSalaryGather();
double totalHours = 0;
double averageHours = 0;
double averageSalary = 0;
double totalSalary = 0;
double averageGroupSalary = 0;
double totalGroupSalary = 0;
int countOfArray = 0;
for (int i = 0; i < empInfoArray.length; i++) {
if (!(empInfoArray[0] == null)) {
totalSalary = totalSalary + Double.parseDouble(empInfoArray[i][1]);
totalHours = totalHours + Double.parseDouble(empInfoArray[i][2]);
totalGroupSalary = totalGroupSalary + Double.parseDouble(empInfoArray[i][3]);
countOfArray = i;
averageHours = totalHours / (countOfArray + 1);
averageSalary = totalSalary / (countOfArray + 1);
averageGroupSalary = totalGroupSalary / (countOfArray + 1);
String strAverageHourlySalary = Double.toString(averageSalary);
String strAverageHours = Double.toString(averageHours);
String strAverageGroupSalary = Double.toString(averageGroupSalary);
for (int i = 0; i < empInfoArray.length; i++) {
if (!(empInfoArray[i][0] == null)) {
finalOutput = finalOutput + empInfoArray[i][0] + " - " + "$" + empInfoArray[i][1] + "/hr" + " - " + empInfoArray[i][2] + " - " + "$" + empInfoArray[i][3] + "\n";
averageHoursOutput = averageHoursOutput + strAverageHours + "\n";
averageSalaryOutput = averageSalaryOutput + strAverageHourlySalary + "\n";
averageGroupSalaryOutput = averageGroupSalaryOutput + strAverageGroupSalary + "\n";
JOptionPane.showMessageDialog(null, finalOutput + averageHoursOutput + averageSalaryOutput + averageGroupSalaryOutput, "Totals", JOptionPane.PLAIN_MESSAGE );Call the other class's methods. (In general, you
shouldn't even try to access fields from the other
class.) Also you should be looking at an
instance of the other class, and not the class
itself, generally.Would I not call the other classes method's by someting similar as below?:
AverageSalaryCalcAndPrint averageSalaryCalcAndPrint = new AverageSalaryCalcAndPrint();
averageSalaryCalcAndprint.calcAndPrint(); Well... don't break down classes based on broad steps
of the program. Break them down by the information
being managed. I'm not expressing this well...Could you give an example of this? I'm not sure I'm following well.
Anyway, you want one or more objects that represent
the data, and operations on that data. Those
operations include calculations on the data. Other
classes might represent the user interface, and
different output types (say, a file versus the
console).Yes, the requirements is to have a separate class to gather the data, and then another class to calculate and print the data. Is this what you mean in the above? -
How do I use a variable from an Interface class?
Right now I have three classes. First class is called Game and it extends my second class call Parent and also implements my third class call Source. Source is an interface class. I have a variable that I want to use in my Source class named Checker. Now, How do I go among using that variable from my Game class? What should the code look like?
ex.
public class Game extends Parent implements Source
need help badly....ok, what I forgot to tell you guys is that my variable
in my interface class is a boolean type(true or
false). It is set to true now. But I want it to change
to false when a user triggers a button in the Game
class. How do I do this? You don't because you can't. If you have a varaible declared in an interface it must be static and final. It cannot, therefore, be changed. Better head back to the drawing board. -
Not able to pass values to variables in extended Tree class
Hi,
I have a as class that extends from Tree, additionally this
custom class defines
new class level variables as follows:
public class MyTree extends Tree {
public var arrayColl:ArrayCollection;
and i call this tree from mxml as follows:
<customTree:MyTree
arrayColl={list}
xmlns:customTree="../../.*"/>
Though my 'list' collections is not null, when i place an
alert in the constructor of extended tree class
it shows as null.
Please advice.
Thanks,
Luckybelow is the canvas:
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="
http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import mx.collections.IViewCursor;
import mx.collections.ArrayCollection;
import com.citi.ascript.TreeData;
import mx.controls.Alert;
import com.citi.ascript.CitiTree;
public var availableTreeDataColl:ArrayCollection;
public var selectedTreeDataColl:ArrayCollection;
public var treeData:TreeData;
public var srcTree:CitiTree;
public var availableTreeDataArray:Array = [{a:1},
{b:2},
{c:3}
public function formTreeData():void {
var tempColl:ArrayCollection = new
ArrayCollection(availableTreeDataArray);
availableTreeDataColl = new ArrayCollection();
for (var i:int=0; i<tempColl.length; i++) {
var tempTreeData:Object = tempColl
treeData = new TreeData();
treeData.a = tempTreeData.a;
treeData.b = tempTreeData.b;
treeData.c = tempTreeData.c;
availableTreeDataColl.addItem(treeData);
]]>
</mx:Script>
<mx:VBox>
<mx:Label text="Drag & Drop the analysis sections
that you would like to include in the report" width="450"
height="20"/>
<mx:HBox id="treeContainer"
creationComplete="formTreeData();">
<customTree:MyTree treeList={availableTreeDataColl} //
here collection becomes null.
</customTree:MyTree>
</mx:HBox>
</mx:VBox>
</mx:Canvas>
The collection of TreeData is iterated in the customTree to
form xml which will act as dataprovider for tree.
and this canvas is added as a child for a panel in my main
application.
Hope this gives an idea.
Thanks,
Lucky -
Accessing a variable defined in one class from another class..
Greetings,
I've only been programming in as3 for a couple months, and so far I've written several compositional classes that take MovieClips as inputs to handle behaviors and interactions in a simple game I'm creating. One problem I keep coming upon is that I'd love to access the custom variables I define within one class from another class. In the game I'm creating, Main.as is my document class, from which I invoke a class called 'Level1.as' which invokes all the other classes I've written.
Below I've pasted my class 'DieLikeThePhishes'. For example, I would love to know the syntax for accessing the boolean variable 'phish1BeenHit' (line 31) from another class. I've tried the dot syntax you would use to access a MovieClip inside another MovieClip and it doesn't seem to be working for me. Any ideas would be appreciated. Thanks,
- Jeremy
package jab.enemy
import flash.display.MovieClip;
import flash.events.Event;
import jab.enemy.MissleDisappear;
public class DieLikeThePhishes
private var _clip2:MovieClip; // player
private var _clip3:MovieClip; //phish1
private var _clip4:MovieClip; //phish2
private var _clip5:MovieClip; //phish3
private var _clip6:MovieClip; //phish4
private var _clip10:MovieClip; // background
private var _clip11:MovieClip // missle1
private var _clip12:MovieClip // missle2
private var _clip13:MovieClip // missle3
private var _clip14:MovieClip // missle4
private var _clip15:MovieClip // missle5
private var _clip16:MovieClip // missle6
private var _clip17:MovieClip // missle7
private var _clip18:MovieClip // missle8
private var _clip19:MovieClip // missle9
private var _clip20:MovieClip // missle10
private var _clip21:MovieClip // missle11
private var _clip22:MovieClip // missle12
var ay1 = 0;var ay2 = 0;var ay3 = 0;var ay4 = 0;
var vy1 = 0;var vy2 = 0;var vy3 = 0;var vy4 = 0;
var phish1BeenHit:Boolean = false;var phish2BeenHit:Boolean = false;
var phish3BeenHit:Boolean = false;var phish4BeenHit:Boolean = false;
public function DieLikeThePhishes(clip2:MovieClip,clip3:MovieClip,clip4:MovieClip,clip5:MovieClip,clip6:M ovieClip,clip10:MovieClip,clip11:MovieClip,clip12:MovieClip,clip13:MovieClip,clip14:MovieC lip,clip15:MovieClip,clip16:MovieClip,clip17:MovieClip,clip18:MovieClip,clip19:MovieClip,c lip20:MovieClip,clip21:MovieClip,clip22:MovieClip)
_clip2 = clip2;_clip3 = clip3;_clip4 = clip4;_clip5 = clip5;_clip6 = clip6;
_clip10 = clip10;_clip11 = clip11;_clip12 = clip12;_clip13 = clip13;_clip14 = clip14;
_clip15 = clip15;_clip16 = clip16;_clip17 = clip17;_clip18 = clip18;_clip19 = clip19;
_clip20 = clip20;_clip21 = clip21;_clip22= clip22;
_clip3.stage.addEventListener(Event.ENTER_FRAME, onEnterFrame)
function onEnterFrame(event:Event):void
vy1+= ay1;_clip3.y += vy1; vy2+= ay2;_clip4.y += vy2;
vy3+= ay3;_clip5.y += vy3; vy4+= ay4;_clip6.y += vy4;
if (phish1BeenHit ==false)
if(_clip3.y >620)
{_clip3.y = 620;}
if (phish2BeenHit ==false)
if(_clip4.y >620)
{_clip4.y = 620;}
if (phish3BeenHit ==false)
if(_clip5.y >620)
{_clip5.y = 620;}
if (phish4BeenHit ==false)
if(_clip6.y >620)
{_clip6.y = 620;}
if (_clip11.hitTestObject(_clip3) ||_clip12.hitTestObject(_clip3)||_clip13.hitTestObject(_clip3)||_clip14.hitTestObject(_cl ip3)||_clip15.hitTestObject(_clip3)||_clip16.hitTestObject(_clip3)||_clip17.hitTestObject( _clip3)||_clip18.hitTestObject(_clip3)||_clip19.hitTestObject(_clip3)||_clip20.hitTestObje ct(_clip3)||_clip21.hitTestObject(_clip3)||_clip22.hitTestObject(_clip3))
_clip3.scaleY = -Math.abs(_clip3.scaleY);
_clip3.alpha = 0.4;
ay1 = 3
vy1= -2;
phish1BeenHit = true;
if (_clip11.hitTestObject(_clip4) ||_clip12.hitTestObject(_clip4)||_clip13.hitTestObject(_clip4)||_clip14.hitTestObject(_cl ip4)||_clip15.hitTestObject(_clip4)||_clip16.hitTestObject(_clip4)||_clip17.hitTestObject( _clip4)||_clip18.hitTestObject(_clip4)||_clip19.hitTestObject(_clip4)||_clip20.hitTestObje ct(_clip4)||_clip21.hitTestObject(_clip4)||_clip22.hitTestObject(_clip4))
_clip4.scaleY = -Math.abs(_clip4.scaleY);
_clip4.alpha = 0.4;
ay2 = 3
vy2= -2;
phish2BeenHit = true;
if (_clip11.hitTestObject(_clip5) ||_clip12.hitTestObject(_clip5)||_clip13.hitTestObject(_clip5)||_clip14.hitTestObject(_cl ip5)||_clip15.hitTestObject(_clip5)||_clip16.hitTestObject(_clip5)||_clip17.hitTestObject( _clip5)||_clip18.hitTestObject(_clip5)||_clip19.hitTestObject(_clip5)||_clip20.hitTestObje ct(_clip5)||_clip21.hitTestObject(_clip5)||_clip22.hitTestObject(_clip5))
_clip5.scaleY = -Math.abs(_clip5.scaleY);
_clip5.alpha = 0.4;
ay3 = 3
vy3= -2;
phish3BeenHit = true;
if (_clip11.hitTestObject(_clip6) ||_clip12.hitTestObject(_clip6)||_clip13.hitTestObject(_clip6)||_clip14.hitTestObject(_cl ip6)||_clip15.hitTestObject(_clip6)||_clip16.hitTestObject(_clip6)||_clip17.hitTestObject( _clip6)||_clip18.hitTestObject(_clip6)||_clip19.hitTestObject(_clip6)||_clip20.hitTestObje ct(_clip6)||_clip21.hitTestObject(_clip6)||_clip22.hitTestObject(_clip6))
_clip6.scaleY = -Math.abs(_clip6.scaleY);
_clip6.alpha = 0.4;
ay4 = 3
vy4= -2;
phish4BeenHit = true;
if (_clip3.y > 10000)
_clip3.x = 1000 +3000*Math.random()-_clip10.x;
_clip3.y = 300;
_clip3.alpha = 1;
_clip3.scaleY = Math.abs(_clip3.scaleY);
ay1 = vy1 = 0;
phish1BeenHit = false;
if (_clip4.y > 10000)
_clip4.x = 1000 +3000*Math.random()-_clip10.x;
_clip4.y = 300;
_clip4.alpha = 1;
_clip4.scaleY = Math.abs(_clip4.scaleY);
ay2 = vy2 = 0;
phish2BeenHit = false;
if (_clip5.y > 10000)
_clip5.x = 1000 +3000*Math.random()-_clip10.x;
_clip5.y = 300;
_clip5.alpha = 1;
_clip5.scaleY = Math.abs(_clip5.scaleY);
ay3 = vy3 = 0;
phish3BeenHit = false;
if (_clip6.y > 10000)
_clip6.x = 1000 +3000*Math.random()-_clip10.x;
_clip6.y = 300;
_clip6.alpha = 1;
_clip6.scaleY = Math.abs(_clip6.scaleY);
ay4 = vy4 = 0;
phish4BeenHit = false;
var missleDisappear1 = new MissleDisappear(_clip11,_clip3,_clip4,_clip5,_clip6,_clip10);
var missleDisappear2 = new MissleDisappear(_clip12,_clip3,_clip4,_clip5,_clip6,_clip10);
var missleDisappear3 = new MissleDisappear(_clip13,_clip3,_clip4,_clip5,_clip6,_clip10);
var missleDisappear4 = new MissleDisappear(_clip14,_clip3,_clip4,_clip5,_clip6,_clip10);
var missleDisappear5 = new MissleDisappear(_clip15,_clip3,_clip4,_clip5,_clip6,_clip10);
var missleDisappear6 = new MissleDisappear(_clip16,_clip3,_clip4,_clip5,_clip6,_clip10);
var missleDisappear7 = new MissleDisappear(_clip17,_clip3,_clip4,_clip5,_clip6,_clip10);
var missleDisappear8 = new MissleDisappear(_clip18,_clip3,_clip4,_clip5,_clip6,_clip10);
var missleDisappear9 = new MissleDisappear(_clip19,_clip3,_clip4,_clip5,_clip6,_clip10);
var missleDisappear10 = new MissleDisappear(_clip20,_clip3,_clip4,_clip5,_clip6,_clip10);
var missleDisappear11 = new MissleDisappear(_clip21,_clip3,_clip4,_clip5,_clip6,_clip10);
var missleDisappear12 = new MissleDisappear(_clip22,_clip3,_clip4,_clip5,_clip6,_clip10);I would approach it in much the same way as you would in java, by making getters and setters for all of your class variables.
Getters being for returning the values, Setters being for setting them.
So you would make a get function for the variable you want to access ala:
function get1PhishBeenHit():boolean {
return this.phish1BeenHit;
Then to access the value of that variable from outwith the class:
var result:boolean = ClassInstanceName.get1PhishBeenHit(); -
Catch-22: need to assign a local variable within an anonymous class
static boolean showMessage(Window parent, String button0, String button1)
throws HeadlessException {
final Window w = new Window(parent);
Panel p = new Panel(new GridBagLayout());
final Button b[] = new Button[]{new Button(button0), (button1 != null) ? new Button(button1) : (Button)null};
boolean rval[]; //tristate: null, true, false
w.setSize(100, 50);
w.setVisible(true);
//add b[0
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.gridx = 0;
gbc.gridy = 3;
p.add(b[0], gbc);
//add b[1]
if (button1 != null) {
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.gridx = 1;
gbc.gridy = 3;
p.add(b[1], gbc);
w.add(p);
w.pack();
w.setVisible(true);
//actionListener for button 0
b[0].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (e.getSource() == b[0]) {
w.setVisible(false);
rval = new boolean[1];
rval[0] = true;
//actionListener for button 1
if (button1 != null) {
b[1].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (e.getSource() == b[1]) {
w.setVisible(false);
rval = new boolean[1];
rval[0] = false;
while (true) {
try {
if (rval[0] == true || rval[0] == false) //should trigger NullPointerException
return rval[0];
} catch (NullPointerException e) { }
}catch-22 is at
rval = new boolean[1];
rval = false;javac whines: "local variable rval is accessed from within inner class; needs to be declared final"
How do I assign to rval if it's declared final?
Or at the very least, how do I get rid of this error (by all means, hack fixes are okay; this is not C/C++, I don't have to use sanity checks)?
I'm trying to make a messagebox in java without using JOptionPane and I'm trying to encapsulate it in one method.
And I'm far too lazy to make a JNI wrapper for GTK.dcminter wrote:
How do I assign to rval if it's declared final?You don't and you can't. You're not allowed to assign to the local variable of the outer class for extremely good reasons, so forget about trying.
Or at the very least, how do I get rid of this errorIf you don't want the side effect, then just use an inner class variable or a local variable.
If you want the side effect then use a named class and provide it with a getter and setter.
Finally, in this specific case because you're using an array object reference, you could probably just initialise the array object in the outer class. I.e.
// Outer class
final boolean[] rval = new boolean[1];
// Anonymous Inner class
rval[0] = true; // No need to intialize the array.
I declared it as an array so that it would be a tristate boolean (null, true, false) such that accessing it before initialization from the actionPerformed would trigger a NullPointerException.
Flowchart:
is button pressed? <-> no
|
V
Yes->set and return
Is there a way to accomplish this without creating a tribool class? -
Accessing a Sub class variable in a Super Class
Hi ,
Is there any easiest way to access a Subclass Variable in a Super Class.
Class Super1{
Class sub extends Super1
private String substring1;
In my application the 'substring1' values is not null .But all fields in Super1 class are null .
How can i access the value of the Subclass Variable in Super class .
ThanksThis would be a way to make the superclass dependent on subclass behavior. Of course this only makes sense if getSubString() is likely to have multiple different implementations in different subclasses.
public abstract class Super {
public String getString() {
return "SuperString" + getSubString();
protected abstract String getSubString();
public class Sub extends Super {
private String substring;
protected String getSubString() {
return substring;
}Using this just to access a variable whose contents differ from subclass to subclass is overkill. If you want each subclass to provide a different substring, create a constructor with a substring parameter in the superclass instead:public class Super {
private String substring;
protected Super(String substring) {
this.substring = substring;
public String getString() {
return "SuperString" + substring;
public class Sub extends Super {
public Sub() {
super("substring");
} -
Why does a variable set in java class appear null in message body
Hello,
I set my variable in the java class like this:
DocumentProcessor dp = new DocumentProcessor(
control_file, path, working_dir );
Properties prop = new Properties();
prop.put( "user-variable:XMLPUB_BODY_VAR", "from_email" );
dp.setConfig(prop);
dp.process();
and in the control file like this:
<xapi:message id="123" to="${C_EMAIL_ADDR}" attachment="true" content_type="html/text" subject="Remittance Advice for check#${C_CHECK_NUM} ">Hello,
Attached is the remittance advice: #${C_CHECK_NUM}
If you have any queries, please send an email to: ${XMLPUB_BODY_VAR}
The problem is that he XMLPUB_BODY_VAR appears null. Is this a know problem? Any solutions?does anyone know of this bug? I've heard similar problems before where some of the variables in the email content don't mysteriously get replaced.
Is this a known bug?
Maybe you are looking for
-
How to create a schedule to run once?
I am having some problems getting a schedule to run only once. If I leave the repeat_interval empty, the schedule does not run at all. The documentation explains all the options for setting the repeat frequency, but it does not explain how to run it
-
'other driver and xa connection properties
A connection pool is configured through the admin server with a third party driver (specify other for database type). The driver is only on the classpath
-
Problems syncing yahoo contacts to ipod touch Model MB5286 Version 4.2.1
For the last 2 years I have had no trouble updating my yahoo contacts to my ipod touch. I just plugged in my ipod and away it went. More recently, the iTunes format appears to have changed and I no longer see the same iPod information menus as befo
-
Item Pricing date from ref. Invoice not copied into Credit memo request
Hi SAP experts, If a reference invoice includes several pricing dates on item level only the first pricing date will be copied into the credit memo request. Example: Invoice includes three items. First item has pricing date 2007-03-01 and item 20/30
-
How to delete object in Integration Repository SAP PI 7.0
how to delete object in Integration Repository SAP PI 7.0