Using values of two different applications that are from the same class

Hi,
See the following little program
What I can't figure out is
i) How to change the values if I add a button
ii) How to print just app.x1 etc. The way I have it now, it will just print x1, y1 etc, from both app and app1, but I want to be able to distinguish between the two of them so I can use the values.....ie for example add app.x1 and app1.x2 (only using that as an example of what I want to use them for)
I'd really appreciate if anyone could help me out, it's probably simple, but just cant figure it.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class drawLine extends JFrame{
int x1, y1, x2, y2;
JPanel topPanel;
JButton button;
public length l, l3;
public drawLine(){
super("drawLine");
public drawLine(length l){
this.l = l;
topPanel = new JPanel();
button = new JButton("Change");
topPanel.add(button);
getContentPane().add(topPanel, BorderLayout.NORTH);
x1 = 100;
y1 = 100;
x2 = l.x2;
y2 = l.y2;
System.out.println(x1 + " " + y1 + " " + x2 + " " + y2);
/*button.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
l.length();
repaint();
public void hello(){
System.out.println(x1 + " " + y1 + " " + x2 + " " + y2);
public void paint(Graphics g){
draw(g);
public void draw(Graphics g){
g.drawLine(x1, y1, x2, y2);
public static void main(String args[]){
length l1 = new length();
length l2 = (length)l1.clone();
l1.length();
l2.length();
drawLine app = new drawLine(l1);
app.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
app.setSize( 300, 300 );
app.move(0,0) ;
app.setVisible( true );
drawLine app1 = new drawLine(l2);
app1.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
app1.setSize( 300, 300 );
app1.move(300,0) ;
app1.setVisible( true );
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class length implements Cloneable{
String whatlength;
int llength;
int x1 = 100;
int y1 = 100;
public int x2, y2;
public void length(){
whatlength = JOptionPane.showInputDialog("What is the length of the line");
llength = Integer.parseInt(whatlength);
x2 = x1 + llength;
y2 = y1;
public Object clone() {
Object object = null;
try {
object = super.clone();
catch (CloneNotSupportedException exception) {
System.err.println("AbstractSpoon is not Cloneable");
return object;
}

I've tried it like this, ie by adding an int to drawLine and trying to keep an array of lengths, which sortof works, but see the code I have commented out in the button actionListener class. What I thought I'd ba able to do is access the arrays like that.....how come it gives me an exception?
public class drawLine extends JFrame{
int x1, y1, x2, y2;
JPanel topPanel;
JButton button;
public length[] linelength = new length[2];
public drawLine(final length l, final int k){
super("drawLine");
this.linelength[k] = l;
topPanel = new JPanel();
button = new JButton("Change");
topPanel.add(button);
getContentPane().add(topPanel, BorderLayout.NORTH);
x1 = 100;
y1 = 100;
x2 = linelength[k].x2;
y2 = linelength[k].y2;
button.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
//Update the length object int's
linelength[k].getLineLength();
// Copy these ints back to the drawline object
x2 = linelength[k].x2;
y2 = linelength[k].y2;
System.out.println(k + " " + linelength[k].x1 + " " + linelength[k].y1 + " " + linelength[k].x2 + " " + linelength[k].y2);
repaint();
/*********This bit gives me a null pointer exception ********
linelength[0].x1 = linelength[1].x1;
linelength[0].x2 = linelength[1].x2;
linelength[0].y1 = linelength[1].y1;
linelength[0].y2 = linelength[1].y2;
public void paint(Graphics g){
g.clearRect( 0, 0, getWidth(), getHeight() );
draw(g);
public void draw(Graphics g){
g.drawLine(x1, y1, x2, y2);
public static void main(String args[]){
length l1 = new length();
length l2 = (length)l1.clone();
l1.getLineLength();
l2.getLineLength();
drawLine app = new drawLine(l1, 0);
app.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
app.setSize( 300, 300 );
app.move(0,0) ;
app.setVisible( true );
drawLine app1 = new drawLine(l2, 1);
app1.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
app1.setSize( 300, 300 );
app1.move(300,0) ;
app1.setVisible( true );
}

Similar Messages

  • HT4061 How do I consolidate purchases from two different ids that are on the same bank account, and eliminate the extra id without losing any purchases?

    How do I consolidate purchases from two different ids that are on the same bank account, and eliminate the extra id without losing any purchases? I want my music to match on both ipad and computer.

    Purchases are forever tied to the AppleID they were bought with. There is currently no way to consolidate AppleIDs. Sorry.

  • Can i use home sharing when two different apple accounts are on the same computer?

    will home sharing work when two iTunes Libraries are on the same computer?

    Can you be more clear about what you mean. More detail please.
    Is this the solution you are looking for?
    Log in to both user accounts and launch iTunes. Turn on Home Sharing from the 'Advanced' menu at the top of the screen.
    Leave iTunes running and use Fast User Switching to switch between user accounts. You will notice that each user's library of media is available to the other user and you can copy media from the other user to the current user's account.

  • Is there a way to differentiate from two iPod touches that are on the same iTunes acct when using iMessage? When one child sends a message the other gets it and it says it's from our email address.

    Both of my sons have iPod touches. I set them both up on my iTunes account. The problem we are having is when they are using iMessage. When one sends a message the other also receives it. The message is labeled as from my email address. Is there a way to differentiate the 2 iPods?

    See:
    MacMost Now 653: Setting Up Multiple iOS Devices For Messages and FaceTime

  • Can I use one Apple TV device on two different HD televisions to view the same info from a mini Mac?

    Can I use one Apple TV device on two different HD televisions to view the same info from a mini Mac?

    Welcome to the Apple Community Lschaef5318.
    You need one Apple TV for each TV.

  • HT4262 I have two networks one each in two cities.  Both are named the same but require different passwords. I am at my second location but cannot connect to his wifi network. How do I delet one network so I can connect to my second network?

    I have two networks one each in two cities.  Both are named the same but require different passwords. I am at my second location and cannot connect to this wifi network. How do I delet one network so I can connect to my second network?

    Just go to the wireless network preferences and empty out all the stored wireless networks.. then scan and connect to the local wireless.
    Select them and tap the - button below it.
    Once they are emptied out.. it might be good to reboot the computer with the remember networks unchecked.
    Start with a clean slate.

  • So my iphone 4 that is using ios5 keeps freezing when i want to dial, or receive call. i can use all my other apps but cant use the phone to call because the freezing problem. i know some people that are having the same problem too. what can i do?

    so my iphone 4 that is using ios5 keeps freezing when i want to dial, or receive call. i can use all my other apps but cant use the phone to call because the freezing problem. i know some people that are having the same problem too. what can i do?

    I got the same problem. The percentage of getting this problem is around 10% of all my dial/receive calls.
    The problem usually appears when I receive calls. The phone app will freeze, and I cannot dial or receive calls even I closed the phone app, however, most other apps work properly.
    Once this problem happens, I will not be able to turn off the phone by holding sleep button, the only way I can get rid of it is holding sleep and home button at the same time to reset the iphone.

  • How do I create a graph with two different y-axis variables with the same x-axis (therefor having two curves)?, How do I create a graph with two different y-axis variables with the same x-axis (therefor having two curves)?

    How do I create a graph with two different y-axis variables with the same x-axis (therefor having two curves)?, How do I create a graph with two different y-axis variables with the same x-axis (therefor having two curves)?

    Hi Libby,
    Select all three columns of data. All three must be 'regular' columns, not Header columns, and the X values must be in the leftmost column.
    Click the Charts button and choose the Scatter chart.
    The resulting chart will initially show only the first and second columns of data, and the selection will have been reduced to show this.
    Click the gear icon at the top left of the selection and choose Share X Values.
    You should see a result similar to this:
    Notes:
    The values on my sample table contain a random element, so they have changed from thhe first image to the second.
    The chart is as created by Numbers, with two edits:
    Data points have been connected with curves, using the Chart nspector.
    The curves were selected and their stroke increased to 2pts, using the stroke formating button in the format bar.
    Regards,
    Barry

  • Issues with processing messages on one receive port causes problems on all the receive ports that are on the same handler

    Greetings,
    An integrator installed biztalk in our environment to process the hl7 message flow between their source application(s) and several receiving applications. We've had problems with this set-up for a while now because some receiving applications sometimes have
    problems processing the messages. Be it either because there's problems with the server that processes the messages of a certain port or because there's problems with the software/daemon/service that needs to process these messages.
    The main problem with this, is that the receiving end of this isn't under our control nor under control of the integrator, but when one receive port isn't processing their messages for a while it causes a problem with all the receive ports that are on the
    same handler. So other receive ports start noticing a slow-down of their incoming messages until after a while nothing gets through anymore.
    What is the best practice to prevent these kind of problems? Should we just create a handler for every receive port? Because that seems a bit overkill.
    Thanks in advance.

    What do you mean exactly with this question?
    "Can you provide some more detail like BizTalk the receiver? "
    The adapters are mainly file and MLLP, the MLLP adapters are already seperated from the file adapters (a handler for MLLP and a handler for file).
    The problem with all the receive ports is that when one receive port isn't processing its messages (usually caused by the software processing the messages) the other receive ports on the same handler receive their messages/files a lot slower. If for any
    reason the problem isn't fixed soon, the other receive ports on the same handler actually stop receiving any messages at all.
    Isolating the receive port that causes the problems like la Cour suggested can work, but next time it might be another port that experiences this issue. So we are looking for a way to make sure the whole message flow isn't hindered by one port (whichever
    port) that can't process its messages. Or rather by one receiving software that can't process its messages.

  • There are many apps I purchased for my android phone that are exactly the same for the iPhone, do I have to buy these again or would the license transfer?

    There are many apps I purchased for my android phone that are exactly the same for the iPhone, do I have to buy these again or would the license transfer?

    Yes you need to buy them again. Apps written for one device will not run on the other.

  • Linux users cannot open Firefox on multiple systems that are mounting the same network drive as their home directory

    I am supporting a user who is logging into multiple linux systems that all have the same /home directory mounted to a network filer.
    When the user opens firefox on one system, he is unable to open firefox on other systems.
    I'm assuming this is because firefox is storing his profile in /home.
    These are Centos 5.4 x64 systems, authenticatiing to a Windows 2003 Domain. The filer that hosts the home directories is a NetApp with both CIFS and NFS permissions enabled on the volume that /home resides. We are using the version that came with the Centos installation, 3.0.12

    So while this worked well for my computer at home, it does not work for the actual computer the disk is mounted on.  If I try to mount the disk as the "office" user, the computer rejects the connection to itself and tells me to access it locally.  Any ideas on how to handle this?  Thanks again.
    dlr

  • Two different WCS instances, pointing to the same database

    Hi,
    for some unknown reason that came from the architecture fellows, I need to install 02 instances of WCS pointing to the same database server. I mean, both instances would need to "share" the database. They don't want a cluster schema because they need to have the option to deploy the app in one instance and, if wverything is ok, deploy to the remaining instance.
    Do you know if such architecture is possible? I did the installation of one instance(instance A), but when trying to install the instance B referring to A's database, I get a ton of errors.
    Any advice is much appreciated.
    Regards,
    Vinicius
    Edited by: 1000164 on Apr 15, 2013 8:18 PM

    Hi,
    This is not the way Sites has been designed. Each instance should have their own schema and repository unless the two instances work as a Sites cluster.
    So what you're trying to achieve is not possible using your approach. What I could suggest is to install two separate instances on its own, create the necessary data model, asset configurations, templates, etc. in one instance and replicate it to the other instance by publishing it to the other instance using real-time publish. If you use LDAP or any other supported directory server you would be able to use a singe directory for both sites instances.
    Regards,
    Rodney

  • How do I FaceTime using two iPhones that are on the same iTunes account?

    My husband and I share the same iTunes account for both of our iPhones. How can we FaceTime each other?

    Pretty easy actually.  I had this same issue a few weeks ago when I got my wife an iPhone.
    Go to Settings > FaceTime > int there, it will say recieve calls at "X" amount of locations.  When you open that, you can check and uncheck email addresses and phone numbers.  You can also add and/or remove email addresses.
    Once you do this, you will want to go into Messages and do the same thing there as well.  Otherwise you will recieve each others iMessages too.
    Good Luck!!  Cheers!

  • How to use two different versions of Firefox at the same time on Snow Leopard?

    I recently upgraded to Firefox 4.0 on my 27" iMac running Snow Leopard 10.6.7.
    Previously, I was using Google's "Page Speed" along with Firebug in Firefox 3.6.15 to optimize images in my web pages, and to find other areas to optimize.
    Page Speed is not yet compatible with Firefox 4.0. I wrote to Google about this some time ago -- no answer yet.
    If I run Firefox 3.6.15 in order to use Page Speed, I run into a few problems afterward when I start using Firefox 4.0 again, since they both use the same "Firefox" folder in my "Application Support" folder.
    How can I set it up so that I can have two separate "Firefox" folders in my "Application Support" folder?
    Or is there an easier way to use two different versions of Firefox simultaneously, even if one has extensions and/or plug-ins installed which are not compatible with the other version?
    Thanks for a great browser!

    Please disregard my question. I just conducted more web search and learned how to use Firefox's profile manager in order to make a separate profile for Firefox 3.6.15.
    You can find instructions on this page:
    http://support.mozilla.com/en-US/kb/Managing%20profiles#os=mac&browser=fx35
    '''A small tip:'''
    If your Firefox app is named anything other than "Firefox" -- say for example "Firefox 3.6.15" -- when you follow the instructions at the above link, make sure you escape the blank space that is before the version number by adding a backward slash before it, when you type the command string in the Terminal. In other words, in that string, you should use this:
    Firefox\ 3.6.15
    I hope that helps someone.
    WW

  • How to rename two external hdd's, that are exactly the same brand and model, in order to distinguish?

    Hello again.
    First of all excuse me if I mistype anything or fail to use some terms correctly. English is not my mother tongue and I am kind of new to MacBooks.
    Here's my problem.
    I've got a macbook pro (yosemite 10.10.1, retina, 15", late 2013, 8gb memory, 250gb ssd), and I am using an external hard drive which I found to be quite good for what I wanted (in case it matters it's the lacie porsche design 2TB USB3).
    I wanted one more external hard drive, and since I was satisfied with the one I had bought before, I decided to go for that one again.
    Now the thing is that, when I go to finder I see 2 disks with the same name (and their "share" partitions) and I don't know which is which.
    I'll try to post a screenshot that might clear things out.
    What I would like to do would be to somehow rename the second disk so it appears in the finder as (for example) Lacie1 and Lacie Share1.
    Apparently, the system kinda thinks in a similar way as I do.
    As you can see below, it has done exactly what I want to do in Lacie's manager (or however it's called), but that does not appear in finder.
    (some words are in Greek, but you'll get the point)
    So, is there any way I can do something that will make the disks appear like that in finder so I can differentiate among them?
    Any help would be greatly appreciated.

    Connect the external HDD to the MBP.  Click in the title below the icon two times.  It should then allow you to change the name.
    See this example:
    Ciao.

Maybe you are looking for

  • Xcelsius 2008 SP4 won't work on Win 7 but does on XP ?

    Hi I posted this a few weeks ago but no one has replied thought I'd try again it is really anoying I have to type everything in word and cut and paste into Xcelsius Touching any key on keyboard locks up Xcelsius Mouse OK SP4   Posted: Feb 1, 2012 2:3

  • New MacBook Pro, FileVault Locked in Perpetual Encryption, Kills Battery

    I have a brand new (well, it's about 2 weeks old now) MacBook Pro (2.8 i7, 1 TB, 16 GB, Iris Pro 1536 MB). Love it. When I initially set up this device after removing it from its box, I opted to enable FileVault encryption. Since then, however, FileV

  • Catalog in LR

    I have a couple of noobie questions for you guys. I have a NAS server where I store my pictures after downloading them.  I keep my pictures there because the NAS is a RAID 1 drive and this way I do not risk lossing anything. I wanted to store my LR c

  • BPEL process to Insert XML into DB using pl/sql stored proc

    Hi, We have created a BPEL process in which we are taking input request and store it into Oracle Database using PL/SQL proc. We have been unsuccessful in doing so because the data stored in table has root element missing. Has any body done this (inse

  • Install Acrobat Pro DC on second computer

    I keep getting a message "Download Acrobat Pro DC from URL www.adobe.com/go/getacrobatdc and it does not work.