• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 236
  • Last Modified:

use Button"jana"in action performed

hi...
i have problem with button.. exactly, i want to pass the value from button"jana"  to another environment or class.. when user click the "generate" button it will get value from before operation then pass to some else... please how...

here the sub code
[ code]
public void actionPerformed(ActionEvent e){
  if(e.getSource() == jana){
   ???????          }

//get value from this operation:
if(first == 2){  //b1
        g.drawLine(325, 225, 395, 225); //line s11&b1            3
        g.drawLine(325, 255, 325, 225); //line s9&s11            2
        g.drawLine(325, 285, 325, 255); //line s1&s9            1
        g.drawLine(425, 285, 325, 285); //line s0&s1            0
      // ????? must return coordinate x,y to actionPerformed above.... how?
        }

[/code]
..... hope will give me some guide
0
miraShamiera
Asked:
miraShamiera
  • 15
  • 10
  • 6
1 Solution
 
CI-Ia0sCommented:
I'm not sure I fully understand your question, but I'll take a stab at it anyway...

To pass the info from "jana" to another class, you can do one of 3 things...
1. Create an object of that class (with arguments of the value of jana) and call one of it's methods:
OtherClass objectOfOtherClass = new OtherClass(janaValue);

2. Create an object of that class and call one of it's methods, passing the jana value to said method:
OtherClass objectOfOtherClass = new OtherClass();
objectOfOtherClass.otherClassMethod(janaValue);

3. Declare a method of the other class as static and call it directly, passing the jana value:
OtherClass.otherClassMethod(janaValue);
0
 
miraShamieraAuthor Commented:
i will give you the spesific code n can u trace it... i have onlyone class n the all operation in that  main class.

when user click button jana, it will get the value coordinate (x,y) from other method...
{code explaination}.......
[code]

*********************************************************
public void init() {
jana=new Button("Jana VRML");
   jana.setBounds(510, 200, 100, 30);
   jana.addActionListener(this);

 }//end init()
*********************************************************

public boolean mouseDown(Event evt, int x, int y) {
    if (kira == 0) {  
         if( 380 < x && x < 400 && 220 < y && y < 240)  { //b1
            if(kira == 0)
               first = 2;
            else if (kira == 1)
               second = 2;
            kira++;
            repaint();
            System.out.println("blok1 telah dipilih");
           return true;
          // can i add return (x,y) here
        }

**********************************************************

public void actionPerformed(ActionEvent e){
      if(e.getSource() == jana){
                Button jana = (jana)e.getSource();
      System.out.println("Label of button pressed = " + source.getX() );
      //blok[i].getX();
        }

        else if (e.getSource()==padam){
        // refresh();
                 }
            
}  //end of actionPerformed
**********************************************************
[/code]

.....where can i return value(x,y) n pass it to other class(mean create new class) to get the value after user click Button "jana"

0
 
expertmbCommented:
// can i add return (x,y) here
you cannot add the return statement (x,y)

>>where can i return value(x,y) n pass it to other class(mean create new class) to get the value after user click Button "jana"
instead if you have the other class reference/object/instance then write a method in other class then pass the
x, y values.

public boolean mouseDown(Event evt, int x, int y) {
    if (kira == 0) {  
         if( 380 < x && x < 400 && 220 < y && y < 240)  { //b1
            if(kira == 0)
               first = 2;
            else if (kira == 1)
               second = 2;
            kira++;
            repaint();
            System.out.println("blok1 telah dipilih");
           otherclassObject.setXY(x, y);
           return true;
          // can i add return (x,y) here
        }
 
 
in otherclass
otherclassObject.setXY(int x, int y){
 this.x = x;
 this.y = y;
}

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
expertmbCommented:
in other class

int x;
int y;

public void setXY(int x, int y){
 this.x = x;
 this.y = y;
}
0
 
miraShamieraAuthor Commented:
excuse me :

it is"
in otherclass
otherclassObject.setXY(int x, int y){
 this.x = x;
 this.y = y;
}

and  

in other class

int x;
int y;

public void setXY(int x, int y){
 this.x = x;
 this.y = y;
}

is the same operation or...

i must add
[code]
public boolean mouseDown(Event evt, int x, int y) {
    if (kira == 0) {  
         if( 380 < x && x < 400 && 220 < y && y < 240)  { //b1
            if(kira == 0)
               first = 2;
            else if (kira == 1)
               second = 2;
            kira++;
            repaint();
            System.out.println("blok1 telah dipilih");
           otherclassObject.setXY(x, y);
           return true;
          // can i add return (x,y) here
        }
 
 
in otherclass
otherclassObject.setXY(int x, int y){
 this.x = x;
 this.y = y;
}
[/code]

then create new class for this operation
[code]
in other class

int x;
int y;

public void setXY(int x, int y){
 this.x = x;
 this.y = y;
}
[/code]

sorry my programming to bad, hope u will explain deply...

0
 
expertmbCommented:
public int[] mouseDown(MouseEvent evt, int x, int y) {
    if (kira == 0) {
         if( 380 < x && x < 400 && 220 < y && y < 240)  { //b1
            if(kira == 0)
               first = 2;
            else if (kira == 1)
               second = 2;
            kira++;
            repaint();
            System.out.println("blok1 telah dipilih");
           otherclassObject.setXY(x, y);
           return true;
          // can i add return (x,y) here
   }

   int a[] = {x,y};
   return a;

}
0
 
miraShamieraAuthor Commented:
i can't use int[] cause the statement of coordinate (x, y) are not integer.. they are arrange coordinate...

i give u the source code fully, so u can know deeply what i'm do it... Can?.... i use java n jdk1.3.1..
0
 
expertmbCommented:
plz post the code.
0
 
miraShamieraAuthor Commented:
[code]

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;

//for pass value to vrml world
import vrml.external.field.*;
import vrml.external.exception.*;
import vrml.external.Node;
import vrml.external.Browser;

/************************************************************
                            class help
 *************************************************************/
public class help extends java.applet.Applet implements ActionListener
{
      Label blok1;
      Label blok2;
      Label blok3;
      Label blok4;
      Label blok5;
      Label blok6;
      Label blok7;
      //int x, y; add follow what have told me
      Button jana,padam;
      private int blok[] = new int [29]; //bilangan bola
      private int laluan[] = new int [33];//bilangan line yg ada
      private int chosen = 0, kira, first, second, step;

/*************************************************************
                  void init()
*************************************************************/
  //initializes the layout
  public void init() {
        setLayout(new BorderLayout(0,0));
        setSize(800,310);//saiz window applet
      setBackground(Color.gray);

      for (int i = 0; i<29; i++)
         blok[i]=0;

      for (int i=0; i<33; i++)
         laluan[i]=0;
      kira = 0;
      first =0;
      second = 0;
      step = 0;

      blok1=new Label("Radioterapi");
        blok1.setBounds(350, 200, 70, 15); //blok1
        blok2=new Label("Wad Bersalin");
        blok2.setBounds(220, 230, 80, 15); //blok2
        blok3=new Label("Kaji Saraf");
        blok3.setBounds(230, 180, 60, 15); //blok3
        blok4=new Label("Wad Kecemasan");
        blok4.setBounds(200,65, 100, 15); //blok4
        blok5=new Label("Urologi");
        blok5.setBounds(360,40, 60, 15); //blok5
        blok6=new Label("Perkhidmatan Darah");
        blok6.setBounds(200,20, 120, 15); //blok6
        blok7=new Label("UKM");
        blok7.setBounds(100,200, 60, 15); //blok7
      jana=new Button("Jana VRML");
        jana.setBounds(510, 200, 100, 30);
        jana.addActionListener(this);
        padam=new Button("Padam");
        padam.setBounds(610, 200, 100, 30);
        padam.addActionListener(this);
   }//end init()

/************************************************************
            public void actionPerformed(ActionEvent e)
*************************************************************/
 public void actionPerformed(ActionEvent e){ //call dr "addActionListener"
          if(e.getSource() == jana){
      // hantarJana.setXY(x, y);add follow what have told me
      //System.out.println("Label of button pressed = "+ x );
      //blok[i].getX();
      }
           else if (e.getSource()==padam){
                }
}  //end of actionPerformed

/************************************************************
            boolean handleEvent(Event evt)
 *************************************************************/
   //handles events
  public boolean handleEvent(Event evt)   {
      if (evt.id == Event.WINDOW_DESTROY) System.exit(0);
      return super.handleEvent(evt); }

/************************************************************/         boolean mouseDown(Event evt, int x, int y)//for mouse clicks
 ************************************************************/

 public boolean mouseDown(Event evt, int x, int y) {
       if (kira == 0) {

          if( 380 < x && x < 400 && 220 < y && y < 240)  { //b1
            if(kira == 0)
               first = 2;
            else if (kira == 1)
               second = 2;
            kira++;
            repaint();
            System.out.println("blok1 telah dipilih");
           //hantarJana.setXY(x, y); add follow what have told me
           return true;
         }

         else if(280 < x && x < 300 && 250 < y && y < 300){ //b2
            if(kira == 0)
               first = 3;
            else if (kira == 1)
               second = 3;
            kira++;
            repaint();
            System.out.println("blok2 telah dipilih");
            return true;
         }


         else if(280 < x && x < 300 && 200 < y && y < 220){ //b3
            if(kira == 0)
               first = 4;
            else if (kira == 1)
               second = 4;
            kira++;
            repaint();
            System.out.println("blok3 telah dipilih");
            return true;
         }

         else if(250 < x && x < 270 && 80 < y && y < 100){ //b4
            if(kira == 0)
               first = 5;
            else if (kira == 1)
               second = 5;
            kira++;
            repaint();
            System.out.println("blok4 telah dipilih");
            return true;
         }
         else if(370 < x && x < 390 && 60 < y && y < 80){ //b5
            if(kira == 0)
               first = 6;
            else if (kira == 1)
               second = 6;
            kira++;
            repaint();
            System.out.println("blok5 telah dipilih");
            return true;
         }
         else if(210 < x && x < 230 && 40< y && y < 60){ //b6
            if(kira == 0)
               first = 7;
            else if (kira == 1)
               second = 7;
            kira++;
            repaint();
            System.out.println("blok6 telah dipilih");
            return true;
         }

         else if(100 < x && x < 120 && 230 < y && y < 250){ //b7
              if(kira == 0)
                 first = 8;
              else if (kira == 1)
                 second = 8;
              kira++;
              repaint();
              System.out.println("blok7 telah dipilih");
              return true;
              }

      }// end of (if count==0)


      if (kira == 3) {//count=3,pilihan utk reset
          if(500 < x && x < 800 && 0 < y && y < 15 ||
             500 < x && x < 800 && 60 < y && y < 100 )  {
            init();
            repaint();
            return true;
         }
      }
      else {
         if(500 < x && x < 800 && 0 < y && y < 15)  {
            init();
            repaint();
            return true;
         }
         else if(500 < x && x < 800 && 60 < y && y < 100)  {
            step=1;
            kira=3;
            repaint();
            return true;
         }
      }

      return true;

   }// end of mouseDown(Event evt, int x, int y)

/************************************************************
                       public void paint( Graphics g )
*************************************************************/

   public void paint( Graphics g )
   {
      add(jana);
      add(padam);
      g.setColor(Color.lightGray);
      g.fillRect(500, 0, 300, 310); // draw text box on the right
      g.setFont(new Font("Times Roman", Font.BOLD, 13));
      g.setColor(Color.blue);     // draw text on the right "RESET"
      g.drawString("RESET", 522, 15);
        g.drawString("**********************************************************", 505, 30);
      g.setColor(Color.black);

      if(kira == 0) {
        g.drawString("klik pada lokasi yang hendak dituju", 505, 70);
      }

      else if (kira == 3) {
         g.drawString("klik reset untuk memadam", 522, 60);
         g.drawString("kawasan yang telah dipilih :",522, 75);
         //g.drawString("kawasan yang di pilih", 515, 105);
         g.setColor(Color.blue);
         g.drawString("RESET", 525, 100);
      }

      else {
         g.drawString("klik laluan untuk mendapatkan", 522, 60);
        // g.drawString("untuk mendapatkan", 511, 90);
         g.drawString("laluan ke lokasi pilihan :", 522, 75);
         g.setColor(Color.blue);
         g.drawString("LALUAN", 525, 100);
      }

      g.setColor(Color.lightGray);    //warna utk line
      //utk menunjukkan laluan yang ada
      g.drawLine(425, 285, 325,285);  //line s0&s1            0
      g.drawLine(325, 285, 325, 255); //line s1&s9            1
      g.drawLine(325, 255, 325, 225); //line s9&s11            2
      g.drawLine(325, 225, 395, 225); //line s11&b1            3
      g.drawLine(325, 255, 285, 255); //line s9&b2            4
        g.drawLine(325, 255, 325, 205); //line s11&s13      5
        g.drawLine(325, 205, 285, 205); //line s13&b3            6
        g.drawLine(325, 205, 325,  85); //line s13&s15      7
        g.drawLine(325,  85, 295,  85); //line s15&s20      8
        g.drawLine(295,  85, 255,  85); //line s20&b4            9
        g.drawLine(325,  85, 325,  65); //line s15&s18      10
        g.drawLine(325,  65, 375,  65); //line s18&b5            11
           g.drawLine(325,  65, 325,  45); //line s18&s17      12
      g.drawLine(325,  45, 295,  45); //line s17&s19      13
        g.drawLine(295,  45, 215,  45); //line s19&b6            14
        g.drawLine(325, 285, 185, 285); //line s1&s2            15
        g.drawLine(185, 285, 185, 255); //line s2&s10            16
        g.drawLine(185, 255, 185, 235); //line s10&s12      17
        g.drawLine(185, 235, 105, 235); //line s12&b7            18
        g.drawLine(185, 285,   5, 285); //line s2&s3            19
        g.drawLine(  5, 285,   5, 235); //line s3&s4            20
        g.drawLine(  5, 235,   5,   5); //line s4&s5            21
        g.drawLine(  5,   5, 425,   5); //line s5&s8            22
      g.drawLine(425,   5, 425, 285); //line s8&s0            23
        g.drawLine(325,  45, 325,   5); //line s17&s7            24
      g.drawLine(295,  85, 325,  45); //line s20&s17      25
      g.drawLine(255,  85, 185,  85); //line b4&s16            26
        g.drawLine(215,  45, 185,  45); //line b6&s21            27
        g.drawLine(285,  205, 185,205); //line b3&s14            28
        g.drawLine(285,  255, 185,255); //line b2&s10            29
        g.drawLine(185,  205, 185,235); //line s14&s12      30
        g.drawLine(185,  205, 185,  5); //line s14&s6            31
        g.drawLine(105,  235,   5,235); //line b7&s4            32

      if (step == 1) {//step mula
         g.setColor(Color.red);

      //sambungan utk setiap blok(b) utk digenerate laluan
      if(first == 2){  //b1
        g.drawLine(325, 225, 395, 225); //line s11&b1            3
        g.drawLine(325, 255, 325, 225); //line s9&s11            2
        g.drawLine(325, 285, 325, 255); //line s1&s9            1
        g.drawLine(425, 285, 325, 285); //line s0&s1            0
        }

      else if(first == 3){ //b2
            g.drawLine(325, 255, 285, 255); //line s9&b2            4
            g.drawLine(325, 285, 325, 255); //line s1&s9            1
        g.drawLine(425, 285, 325, 285); //line s0&s1            0
            }

         else if(first == 4){ //b3
            g.drawLine(325, 205, 285, 205); //line s13&b3            6
            g.drawLine(325, 255, 325, 205); //line s11&s13            5
              g.drawLine(325, 255, 325, 225); //line s9&s11            2
            g.drawLine(325, 285, 325, 255); //line s1&s9            1
        g.drawLine(425, 285, 325, 285); //line s0&s1            0
            }

        else if(first == 5){ //b4
            g.drawLine(295,  85, 255,  85); //line s20&b4            9
            g.drawLine(325,  85, 295,  85); //line s15&s20            8
            g.drawLine(325, 205, 325,  85); //line s13&s15            7
            g.drawLine(325, 255, 325, 205); //line s11&s13            5
            g.drawLine(325, 255, 325, 225); //line s9&s11            2
            g.drawLine(325, 285, 325, 255); //line s1&s9            1
          g.drawLine(425, 285, 325, 285); //line s0&s1            0
            }

       else if(first == 6){ //b5
            g.drawLine(325,  65, 375,  65); //line s18&b5            11
            g.drawLine(325,  85, 325,  65); //line s15&s18            10
            g.drawLine(325, 205, 325,  85); //line s13&s15            7
            g.drawLine(325, 255, 325, 205); //line s11&s13            5
            g.drawLine(325, 255, 325, 225); //line s9&s11            2
            g.drawLine(325, 285, 325, 255); //line s1&s9            1
          g.drawLine(425, 285, 325, 285); //line s0&s1            0
            }

      else if(first == 7){ //b6
            g.drawLine(295,  45, 215,  45); //line s19&b6            14
            g.drawLine(325,  45, 295,  45); //line s17&s19            13
            g.drawLine(325,  65, 325,  45); //line s18&s17            12
            g.drawLine(325,  85, 325,  65); //line s15&s18            10
            g.drawLine(325, 205, 325,  85); //line s13&s15            7
            g.drawLine(325, 255, 325, 205); //line s11&s13            5
            g.drawLine(325, 255, 325, 225); //line s9&s11            2
            g.drawLine(325, 285, 325, 255); //line s1&s9            1
          g.drawLine(425, 285, 325, 285); //line s0&s1            0
            }

      else if(first == 8){ //b7
            g.drawLine(185, 235, 105, 235); //line s12&b7            18
            g.drawLine(185, 255, 185, 235); //line s10&s12            17
            g.drawLine(185, 285, 185, 255); //line s2&s10            16
            g.drawLine(325, 285, 185, 285); //line s1&s2            15
          g.drawLine(425, 285, 325, 285); //line s0&s1            0
            }

   }//end step mula

/**********************************************************
            //draw the points
***********************************************************/

//draw the points == point utk bangunan bertukar warna ikut pilihan

      if(first == 1 || second == 1)
         g.setColor(Color.blue);
      else
         g.setColor(Color.blue);
         g.fillOval(420, 280, 20, 20); //s0

    if(first == 2 || second == 2)
          g.setColor(Color.pink);
         else
           g.setColor(Color.black);
           g.fillOval(380, 220, 20, 20);  //b1
             add(blok1);

      if(first == 3 || second == 3)
           g.setColor(Color.pink);
         else
           g.setColor(Color.black);
           g.fillOval(280, 250, 20, 20);  //b2
           add(blok2);

      if(first == 4 || second == 4)
           g.setColor(Color.pink);
         else
           g.setColor(Color.black);
           g.fillOval(280, 200, 20, 20);  //b3
           add(blok3);

      if(first == 5 || second == 5)
             g.setColor(Color.pink);
         else
             g.setColor(Color.black);
           g.fillOval(250,80, 20, 20);  //b4
           add(blok4);

      if(first == 6 || second == 6)
             g.setColor(Color.pink);
         else
             g.setColor(Color.black);
           g.fillOval(370,60, 20, 20);  //b5
            add(blok5);

      if(first == 7 || second == 7)
             g.setColor(Color.pink);
         else
             g.setColor(Color.black);
           g.fillOval(210,40, 20, 20);  //b6
           add(blok6);

      if(first == 8 || second == 8)
             g.setColor(Color.pink);
         else
             g.setColor(Color.black);
           g.fillOval(100,230, 20, 20); //b7
           add(blok7);

//point utk simpang(sn): s1-s21

      if(first == 9 || second == 9)
             g.setColor(Color.white);
         else
             g.setColor(Color.white);
           g.fillOval(320,280, 10, 10);  //s1

      if(first == 10 || second == 10)
             g.setColor(Color.white);
            else
             g.setColor(Color.white);
           g.fillOval(180,280, 10, 10);  //s2

      if(first == 11 || second == 11)
             g.setColor(Color.white);
            else
             g.setColor(Color.white);
           g.fillOval(0,280, 10, 10);  //s3


      if(first == 12 || second == 12)
             g.setColor(Color.white);
            else
             g.setColor(Color.white);
           g.fillOval(0,230, 10, 10);  //s4

      if(first == 13 || second == 13)
             g.setColor(Color.white);
            else
             g.setColor(Color.white);
           g.fillOval(0,0, 10, 10);   //s5

      if(first == 14 || second == 14)
             g.setColor(Color.white);
            else
             g.setColor(Color.white);
           g.fillOval(180,0, 10, 10);  //s6

      if(first == 15 || second == 15)
             g.setColor(Color.white);
            else
             g.setColor(Color.white);
           g.fillOval(320,0, 10, 10);  //s7

      if(first == 16 || second == 16)
             g.setColor(Color.white);
            else
             g.setColor(Color.white);
             g.fillOval(420,0, 10, 10);  //s8

      if(first == 17 || second == 17)
             g.setColor(Color.white);
            else
             g.setColor(Color.white);
             g.fillOval(320,250,10, 10);  //s9

      if(first == 18 || second == 18)
             g.setColor(Color.white);
            else
             g.setColor(Color.white);
             g.fillOval(180,250,10, 10);  //s10


       if(first == 19 || second == 19)
              g.setColor(Color.white);
             else
              g.setColor(Color.white);
              g.fillOval(320,220,10, 10);  //s11

       if(first == 20 || second == 20)
               g.setColor(Color.white);
              else
               g.setColor(Color.white);
               g.fillOval(180,230,10, 10);  //s12

        if(first == 21 || second == 21)
           g.setColor(Color.white);
          else
           g.setColor(Color.white);
               g.fillOval(320,200,10, 10);  //s13


      if(first == 22 || second == 22)
           g.setColor(Color.white);
          else
           g.setColor(Color.white);
               g.fillOval(180,200,10, 10);  //s14

       if(first == 23|| second == 23)
           g.setColor(Color.white);
          else
           g.setColor(Color.white);
               g.fillOval(320,80,10, 10);  //s15

        if(first == 24 || second == 24)
           g.setColor(Color.white);
          else
           g.setColor(Color.white);
               g.fillOval(180,80,10, 10);  //s16


      if(first == 25 || second == 25)
           g.setColor(Color.white);
          else
           g.setColor(Color.white);
               g.fillOval(320,40,10, 10);  //s17

        if(first == 26 || second == 26)
             g.setColor(Color.white);
            else
             g.setColor(Color.white);
               g.fillOval(320,60,10, 10);  //s18

        if(first == 27 || second == 27)
           g.setColor(Color.white);
         else
           g.setColor(Color.white);
               g.fillOval(290,40,10, 10);  //s19

        if(first == 28 || second == 28)
           g.setColor(Color.white);
         else
           g.setColor(Color.white);
               g.fillOval(290,80,10, 10);  //s20

        if(first == 29 || second == 29)
                 g.setColor(Color.white);
               else
                 g.setColor(Color.white);
               g.fillOval(180,40,10, 10);  //s21

}//end of void paint( Graphics g )
}// end of applet
0
 
miraShamieraAuthor Commented:
what i want to do is, when after, the path(line) is generate... then i will click at JanaVRML... so i want to get the coordinate from the blok i selected before.. Means, i will click at the blok( like urologi) then i click JANAAN (right side) then the red line will appear.. So, want i want is, afterthat i will click the Jana VRML n it will get/catch the coordinate of urologi(which i select before)..

... sorry if the source code too long and hard to understand.. but it easy exactly...
0
 
expertmbCommented:
in mouseDown()
all the if and else statements return true.
this method return always "true".

where this mouseDown() is called?

>>i can't use int[] cause the statement of coordinate (x, y) are not integer.. they are arrange coordinate...
you can use this array, you are interested in x, y which this array returns.
0
 
miraShamieraAuthor Commented:
can u get the applet viewer?... get the output?..

when success run the code, u will see on the right there have statement like
RESET... okey, try to click on any round (in black) then click on the right(LALUAN)... u will know what i am try to do...

in mouseDown()
all the if and else statements return true.
this method return always "true".
>>>---yes...

where this mouseDown() is called?

it call when we click on that round (in black)...

please...

you can use this array, you are interested in x, y which this array returns.
>> i want to return value (x, y) for know which round(in black) we are click...
I want to pass the value to other class, when i click button Jana VRML... how?

Are u know aboout linking java + vrml- use EAI?..
0
 
expertmbCommented:
>>Are u know aboout linking java + vrml- use EAI?..
:-( dont know.

class otherClass{

 private int x,y;
 
 public void setXY(int x, int y){
   this.x = x;
   this.y = y;
 }

}



//in help.java

otheClass object;

//some where this otherClass object is initialized

public boolean mouseDown(MouseEvent evt, int x, int y) {
  //your code
   
  //before return statement
  object.setXY(x,y);
 
  return true;
}
0
 
miraShamieraAuthor Commented:
i have done it.. but the error find...
..... i create new class name 'hantarJana"...

so i declare inside help.java the class,
hantarJana hantar=new hantarJana( );

but the error found:
help.java:38: cannot resolve symbol
symbol  : class hantarJana  
location: class help
      hantarJana hantar = new hantarJana();

in action performed i just put // n no operation there...actually when i click Jana( jana=new Button("Jana VRML");).. si it must get the (x,y) actually n return the value to new class" hantarJana"...

u know how?...


0
 
expertmbCommented:
first compile the hantaraJana.java file. if it is in other package import it.
then compile the  help.java
action performed call this.
hantar.setXY(x,y)
0
 
miraShamieraAuthor Commented:
i still in error... it can not resolve
hantar.setXY(x,y) and  hantarJana hantar = new hantarJana();
0
 
expertmbCommented:
set the classpath, check whether help.java is able to get the hantarJava.java.
0
 
miraShamieraAuthor Commented:
why?...
0
 
miraShamieraAuthor Commented:
i always get error of java lang... how???
0
 
expertmbCommented:
plz post complete exception/error.
0
 
miraShamieraAuthor Commented:
i try to use the sintaks u give...
but it have alot of error...
What times there right now?...

0
 
expertmbCommented:
afternoon , but i am occupied with my proj and many more things, thts why i am not able to give time to ee.
0
 
miraShamieraAuthor Commented:
how to call the button function?... i want after push the button it will carry value from before operation...

mean,
when click this;
if(e.getSource() == jana){
hantarJana.setXY(x, y);

it will pass ed value to class hantarjana....but how?...
0
 
CI-Ia0sCommented:
Add the type of value to be passed as a required argument to hantarjana.setXY(). Then just add it to the arguments you pass:
hantarJana.setXY(x, y, value);
0
 
miraShamieraAuthor Commented:
can u look at my source code above,...

jana.addActionListener(this);


in>>>>>>>>>

 public boolean mouseDown(Event evt, int x, int y) {
       if (kira == 0) {

          if( 380 < x && x < 400 && 220 < y && y < 240)  { //b1
            if(kira == 0)
               first = 2;
            else if (kira == 1)
               second = 2;
            kira++;
            repaint();
            System.out.println("blok1 telah dipilih");
           hantarJana.setXY(x, y); //add follow what have told me
           return true;
         }

then in>>>>
  public void actionPerformed(ActionEvent e)

    public void actionPerformed(ActionEvent e){ //call dr "addActionListener"
          if(e.getSource() == jana){
      hantarJana.setXY(x, y);add follow what have told me
     //System.out.println("Label of button pressed = "+ x );
     blok[i].getX();
     }

then pass the value to class hantarjana...................
public class hantarJana{

      public int x,y;


      public void setXY(int x, int y){
      this.x = x;
       this.y = y;
       System.out.println(x);
      }

}


but it have error... how?
0
 
CI-Ia0sCommented:
What error?
0
 
miraShamieraAuthor Commented:
the erros is:

F:\PENYELAMATKU\help.java:77: cannot resolve symbol
symbol  : variable hantarJana  
location: class help
      hantarJana.setXY(x, y);//add follow what have told me
                         ^
F:\PENYELAMATKU\help.java:79: cannot resolve symbol
symbol  : variable i  
location: class help
           blok[i].getX();
                             ^
F:\PENYELAMATKU\help.java:79: int cannot be dereferenced
      blok[i].getX();
                            ^
F:\PENYELAMATKU\help.java:109: cannot resolve symbol
symbol  : variable hantarJana  
location: class help
           hantarJana.setXY(x, y); //add follow what have told me
           ^
0
 
CI-Ia0sCommented:
First, make sure hantarJana is compiled and resides within the same directory as your class. If it's an inner class, make sure it's declared OUTSIDE of a method.

Second, I think you forgot to put blok[i].getX() in a for-loop. ;)

That should fix it...
0
 
miraShamieraAuthor Commented:
what the statement for get array;
i have array n want to pass it to new class at hantarJana?
0
 
CI-Ia0sCommented:
You can pass it the same way you pass any other variable. For instance, to pass an array of ints:

//Class getting array
public class hantarJana{

public static void getArray(int[] intArray){
//Do whatever you want with intArray in here...
}
}

//Class passing array
public class passArray{
public static void main(String[] args){
//Do whatever till you get an array of ints, then pass it:
hantarJana.getArray(intArray[]);
}
}

NOTE: This only sets the memory addresses of the two arrays to be the same. To actually have a new separate array, you need to copy the data from firstArray[0] to secondArray[0], from firstArray[1] to secondArray[1], etc. (for loops are nice :) ).
0
 
CI-Ia0sCommented:
Thanks. :)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 15
  • 10
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now