A question on JInternalFrame of Swing. Let see the code

Hello everybody,
I am setting up a Frame that contains 2 JInternalFrames in its desktopPane. The first JInternalFrame is to show the map. The second one have some check box. What I wanna do is, when I check the CheckBox in the second JInternalFrame, after getting the result from Database, it show the result on Map. The result will be some red ellipses on the first JInternalFrame.
The code work well with Database. But I really need your help to do with the event on InternalFrame
Thanks in advance !
Quin,
Here is the code of the main Frame:
import java.awt.*;
import java.awt.event.*;
import java.awt.font.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;
import java.io.*;
import java.net.*;
import java.beans.*;
public class MapLocator
     public static void main(String [] args)
          JFrame frame = new DesktopFrame();
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setVisible(true);
Create a desktop frames that contains internal frame
class DesktopFrame extends JFrame implements ActionListener
     public DesktopFrame()
          super("Map Locator v.1.0.0");
          this.setSize(new Dimension(WIDTH,HEIGHT));
          desktop = new JDesktopPane();
          this.setContentPane(desktop);
          this.createInternalFrame(
               new mapPanel(),"Ban do Thanh pho Ho Chi Minh",0,0,480,515);
          this.createInternalFrame(
               new commandPanel(),"Chu thich va tim kiem",480,0,320,515);
Create an internal frame on the desktop.
@param c the component to display in the internal frame
@param t the title ofthe internal frame.
     public void createInternalFrame(JPanel c, String t,int ifx, int ify, int ifwidth, int ifheight)
             final JInternalFrame iframe = new JInternalFrame(t,
             true//resizeable
             ,true//closable
             ,true//maximizable
             ,true//iconifiable
             iframe.getContentPane().add(c);
             desktop.add(iframe);
             iframe.setFrameIcon(new ImageIcon("new.gif"));
             //add listener to confirm frame closing
             iframe.addVetoableChangeListener(new VetoableChangeListener()
                  public void vetoableChange(PropertyChangeEvent event)
                       throws PropertyVetoException
                       String name = event.getPropertyName();
                       Object value = event.getNewValue();
                       //we only want to check attempts to close a frame
                       if(name.equals("closed") && value.equals(Boolean.TRUE))
                            //ask user if it is ok to close
                            int result =
                  JOptionPane.showInternalConfirmDialog(iframe,"OK to close");
                            //if the user doesn't agree, veto the close
                            if(result != JOptionPane.YES_OPTION)
                  throw new PropertyVetoException("User cancel the close",event);
             iframe.setVisible(true);
             iframe.setLocation(ifx,ify);
             iframe.setSize(new Dimension (ifwidth, ifheight));
     private static final int WIDTH = 800;
     private static final int HEIGHT = 600;
     private JDesktopPane desktop;
     private int nextFrameX;
       private int nextFrameY;
        private int frameDistance;
     private JMenuBar menuBar;
     private JMenu fileMenu, viewMenu, searchMenu, windowMenu, helpMenu;
     private JRadioButtonMenuItem javalaf, liquidlaf, motiflaf, windowlaf, threedlaf;
}Below is the code of first JInternalFrame
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
import java.awt.font.*;
import java.awt.geom.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.Random;
import java.util.*;
import com.sun.image.codec.jpeg.*;
Create a canvas that show a map
public class mapPanel extends JPanel
     implements MouseMotionListener, MouseListener
     public mapPanel()
          addMouseMotionListener(this);
          addMouseListener(this);
Unbarrier the comment below to see how the map model work
//Unbarrier this to see -->
         try
            InputStream in = getClass().getResourceAsStream(nameOfMap);
            JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(in);
            mImage = decoder.decodeAsBufferedImage();
            in.close();//Close dong nhap
          catch(ImageFormatException ie)
          { System.out.println ("Error on formating image");}
          catch(IOException ioe)
          { System.out.println ("Error on input/ouput image");}
          catch(Exception e){}
Connect to database
          connDB();
          String addQuery = "";
          try
          Get the relation amongs points
               int idStart = 0;
               int idEnd = 0;
               addQuery ="SELECT IDStart, IDEnd FROM 2Diem";
               rs = stmt.executeQuery(addQuery);
               int incre = 0;
               while(rs.next())
                    idStart = rs.getInt(1);
                    Rel.add(incre, new Integer(idStart));
                    incre ++;
                    idEnd = rs.getInt(2);
                    Rel.add(incre, new Integer(idEnd));
                    incre ++;
     Load the Coordination of the points to hash table
               int idPoint = 0;
               int XP = 0;
               int YP = 0;
               addQuery ="SELECT IDDiem, CoorX, CoorY FROM Diem";
               rs = stmt.executeQuery(addQuery);     
               while(rs.next())
                    idPoint = rs.getInt(1);
                    XP = rs.getInt(2);
                    YP = rs.getInt(3);
                    hashX.put(new Integer(idPoint), new Integer(XP));
                    hashY.put(new Integer(idPoint), new Integer(YP));
     Create Points to draw the Line
               line = new Line2D[(Rel.size())/2];
               for(int i = 0, k = 0; i < Rel.size();i++, k = k+2)
                    X1 = Integer.parseInt(""+hashX.get(Rel.elementAt(i)));
                    Y1 = Integer.parseInt(""+hashY.get(Rel.elementAt(i)));
                    i++;
                    X2 = Integer.parseInt(""+hashX.get(Rel.elementAt(i)));
                    Y2 = Integer.parseInt(""+hashY.get(Rel.elementAt(i)));
                    line[k/2] = new Line2D.Double(X1,Y1,X2,Y2);
          catch(SQLException sqle){}
     private Hashtable hashX = new Hashtable();
     private Hashtable hashY = new Hashtable();
     private Vector Rel = new Vector(100,10);
     private Vector vecBackX = new Vector(10,2);
     private Vector vecBackY = new Vector(10,2);
     private int X1 = 0, X2 = 0, Y1 = 0, Y2 = 0;
     Draw the image to show
     public void paintComponent(Graphics g)
          super.paintComponent(g);
          Graphics2D g2 = (Graphics2D) g;
          g2.setRenderingHint(
               RenderingHints.KEY_ANTIALIASING,
               RenderingHints.VALUE_ANTIALIAS_ON);
    //     g2.drawImage(mImage,0,0,null);
    Paint the background with light Gray
          g2.setPaint(Color.lightGray);
          g2.fill(new Rectangle2D.Double(0,0,480,480));          
         fillBack(g2);
    Draw the street with its border is white, its background is orange
         g2.setPaint(Color.white);
          g2.setStroke(new BasicStroke(14,BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
          for(int k = 0; k < Rel.size()/2; k++)
               g2.draw(line[k]);
          g2.setPaint(Color.orange);
          g2.setStroke(new BasicStroke(10,BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
          for(int k = 0; k < Rel.size()/2; k++)
               g2.draw(line[k]);
     Draw the grid on map
          g2.setPaint(Color.white);
          g2.setStroke(new BasicStroke(1));
          drawGrid(g2);
          if(point != null)
               g2.setPaint(Color.red);
               g2.fillOval(point.x - 3, point.y - 3, 7, 7);
Draw the Background with tree and water
@param g2 the Graphics2D that used to draw shapes
     private void fillBack(Graphics2D g2)
          Draw the background for map
          try
               int BackX = 0;
               int BackY = 0;
               int incre = 0;
               backGround = new GeneralPath[3];
               for(int idBack = 1; idBack <= 3; idBack++)
Since we use the vector for each background(tree / water), we have to
refresh the vector before it can add new path inside
                    vecBackX.clear();
                    vecBackY.clear();
                    String addQuery = "SELECT CoorX, CoorY FROM BackCoor WHERE "
                    + " IDBack =" + idBack;
                    rs = stmt.executeQuery(addQuery);
                    while(rs.next())
                         BackX = rs.getInt(1);
                         BackY = rs.getInt(2);
This will take the point into vector
                         vecBackX.add(incre,new Integer(BackX));
                         vecBackY.add(incre,new Integer(BackY));
                         incre++;
Design the shapes of path
                         backGround[(idBack - 1)] =
                              new GeneralPath(GeneralPath.WIND_EVEN_ODD);
                         backGround[(idBack - 1)].moveTo(
                              Integer.parseInt(""+vecBackX.elementAt(0)),
                              Integer.parseInt(""+vecBackY.elementAt(0)));
                         for(int i = 1; i < vecBackX.size(); i++)
                              backGround[(idBack - 1)].lineTo(
                                   Integer.parseInt(""+vecBackX.elementAt(i)),
                                   Integer.parseInt(""+vecBackY.elementAt(i)));
                         backGround[(idBack - 1)].lineTo(
                                   Integer.parseInt(""+vecBackX.elementAt(0)),
                                   Integer.parseInt(""+vecBackY.elementAt(0)));
                         backGround[(idBack - 1)].closePath();
Here we have 3 Path that represented to tree and water
The first and second one is tree.
The last one is water.
Draw the path now
                         if(idBack == 3)
                              g2.setPaint(Color.cyan);
                              g2.fill(backGround[(idBack - 1)]);
                         else
                              g2.setPaint(Color.green);
                              g2.fill(backGround[(idBack - 1)]);
                         incre = 0;
          catch(SQLException sqle)
               System.out.println ("Khong ve duoc back ground");
Create the grid on map
@param g2 the Graphics2D that used to draw shapes
     private void drawGrid(Graphics2D g2)
          try
             String Query =
             "SELECT * FROM Grid";
             rs = stmt.executeQuery(Query);
             GridX = new Vector(100,2);
             GridY = new Vector(100,2);
             GridW = new Vector(100,2);
             GridH = new Vector(100,2);
             int incr = 0;
             while(rs.next())
                  gridX = rs.getInt(2);
                  gridY = rs.getInt(3);
                  gridW = rs.getInt(4);
                  gridH = rs.getInt(5);
                  GridX.add(incr, new Integer(gridX));
                  GridY.add(incr, new Integer(gridY));
                  GridW.add(incr, new Integer(gridW));
                  GridH.add(incr, new Integer(gridH));
                  incr ++;
             rec = new Rectangle2D.Double[GridX.size()];
             for(int i = 0; i < GridX.size(); i++)
                  gridX = Integer.parseInt(""+GridX.elementAt(i));
                  gridY = Integer.parseInt(""+GridY.elementAt(i));
                  gridW = Integer.parseInt(""+GridW.elementAt(i));
                  gridH = Integer.parseInt(""+GridH.elementAt(i));
                  rec[i] = new Rectangle2D.Double(gridX, gridY, gridW, gridH);
                  g2.draw(rec);
catch(SQLException sqle){}
private Vector GridX, GridY, GridW, GridH;
private int gridX = 0, gridY = 0, gridW = 0, gridH = 0;
Fill the point
     public void placePoint(Graphics2D g2,Point p)
          g2.setPaint(Color.red);
          g2.fill(new Ellipse2D.Double(p.x - 3, p.y - 3, 7,7));
Create connection to Database
     public void connDB()
          System.out.println ("Connecting to Database");
          String fileName = "Pro.mdb";
          String data = "jdbc:odbc:Driver={Microsoft Access Driver " +
     "(*.mdb)};DBQ=" + fileName + ";DriverID=22";
          try
               Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
               conn = DriverManager.getConnection(data,"","");
               stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                    ResultSet.CONCUR_UPDATABLE);
          catch(ClassNotFoundException ce)
          { System.out.println ("Khong tim thay Driver"); }
          catch(SQLException sqle)
          { System.out.println ("Loi SQL trong khi Connect"); }
          Statement stmt = null;
          ResultSet rs = null;
          Connection conn = null;     
This one is the model map to draw
     private String nameOfMap = "map.jpg";
     private BufferedImage mImage;
Initialize the path and shapes to draw
     private Line2D line[];
     private Rectangle2D.Double rec[];
     private GeneralPath backGround[];
     private Point point;
     private int changeColor = 0;
The last one is:
import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
public class commandPanel extends JPanel implements ActionListener
Initial check box
     JCheckBox uyBanNhanDan = new JCheckBox();
     JCheckBox nganHang = new JCheckBox();
     JCheckBox buuDien = new JCheckBox();     
     JCheckBox khachSan = new JCheckBox();     
     JCheckBox benhVien = new JCheckBox();          
     JCheckBox cho = new JCheckBox();     
     JCheckBox nhaHat = new JCheckBox();     
     JCheckBox daiHoc = new JCheckBox();     
     JCheckBox thuvien = new JCheckBox();     
     JCheckBox nhaTho = new JCheckBox();     
     public commandPanel()
          this.setLayout(new BorderLayout());
          this.setBorder(BorderFactory.createCompoundBorder(
                      BorderFactory.createTitledBorder("***Chu dan***"),
                      BorderFactory.createEmptyBorder(5,5,5,5)));
Create the combobox to show information
          uyBanNhanDan.setText("Uy Ban ND Quan");
          nganHang.setText("Ngan Hang");
          buuDien.setText("Buu Dien");
          khachSan.setText("Khach San");
          benhVien.setText("Benh Vien");
          cho.setText("Cho - Mua Sam");
          nhaHat.setText("Nha Hat");
          daiHoc.setText("Dai Hoc - Dao Tao");
          thuvien.setText("Thu Vien - Nha Sach");
          nhaTho.setText("Nha Tho - Chua");
          uyBanNhanDan.addActionListener(this);
          nganHang.addActionListener(this);
          buuDien.addActionListener(this);
          khachSan.addActionListener(this);
          benhVien.addActionListener(this);
          cho.addActionListener(this);
          nhaHat.addActionListener(this);
          daiHoc.addActionListener(this);
          thuvien.addActionListener(this);
          nhaTho.addActionListener(this);
          uyBanNhanDan.setActionCommand("1");
          nganHang.setActionCommand("2");
          buuDien.setActionCommand("3");
          khachSan.setActionCommand("4");
          benhVien.setActionCommand("5");
          cho.setActionCommand("6");
          nhaHat.setActionCommand("7");
          daiHoc.setActionCommand("8");
          thuvien.setActionCommand("10");
          nhaTho.setActionCommand("11");
          JPanel secP = new JPanel();
          secP.setLayout(new GridLayout(5,2));
          secP.add(uyBanNhanDan);
          secP.add(nganHang);
          secP.add(buuDien);
          secP.add(khachSan);
          secP.add(benhVien);
          secP.add(cho);
          secP.add(nhaHat);
          secP.add(daiHoc);
          secP.add(thuvien);
          secP.add(nhaTho);
          this.add(secP,BorderLayout.NORTH);
     public void actionPerformed(ActionEvent event)
          int x = 0;
          int y = 0;
          try
               mapPanel mp = new mapPanel();
               int idDiaDanh = 0;
               if(event.getActionCommand() == "1")
                    idDiaDanh = 1;
               String Query =
               "SELECT CoorX, CoorY FROM MoTa WHERE IDDiaDanh =" + idDiaDanh;
               mp.rs = mp.stmt.executeQuery(Query);
               while(mp.rs.next())
/*I have problem here*/
/*Process the event for me*/          x = mp.rs.getInt(1);
                    y = mp.rs.getInt(2);
                    Graphics g2 = mp.getGraphics();
                    mp.paintComponents(g2);
                         g2.setPaint(Color.red);
                         g2.fill(new Ellipse2D.Double(x - 3, y - 3, 7, 7));     
          catch(SQLException sqle){}

Strings are Objects.
String[] strings = new String[3];
String[0]="abcde";Right here, you are initializing the String array, and the String at index 0.
JButton[] buttons = new JButton[2];
buttons[0].setText("abcde");Right here, you are initializing the JButton array, but not any of the JButtons in the array. You then try to use the setText() method on a null JButton.

Similar Messages

  • Can we see the code of GUI UDF functions

    Hi All,
    Can we see the code of GUI UDF functions?
    Which language it has been written?
    Cheers!
    Samarjit

    Hi,
    Have a look at this blog.
    Is this what you are looking for?
    <a href="/people/venkataramanan.parameswaran/blog/2007/02/06/is-there-a-possibility-to-access-xi-standard-functions-in-user-defined-functions-yes there a possibility to access XI standard functions in User defined Functions?" Yes!</a>
    Regards
    Bhavesh

  • Problem making jar..pls see the code.

    i have some class files in a folder.
    i created a batch file for making jar.
    and when i copy this jar file somewhere and write another batch file to run my java application its showing noclassfound error?.
    pls see the code below and tell me where did i go wrong?
    batch file making jar. 1
    jar cvf SpectrobesUploadSimulator.jar *.class
    pausebatch file to run the application 2
    java SpectrobesSimulator
    pausethe batch file 2 will run if i have the classes in the same directory but when i remove the classes and put the jar its not working.

    i gave the classpaths also
    set CLASSPATH=$CLASSPATH:.:Spectrobes.jar
    java SpectrobesSimulator
    pause

  • I had a big problem i scrape the gift card hard and i cant see the code what should i do??, i had a big problem i scrape the gift card hard and i cant see the code what should i do??

    i have a problem i scrape the gift card hard and i cant see the code what should i do??

    iTunes Store: Invalid, inactive, or illegible codes

  • What can i do if I scratch the itunes card and I can´t see the code?

    what can i do if I scratch the itunes card and I can´t see the code?

    Follow these instructions;  iTunes Store:  Invalid, Inactive, or Illegible codes, http://support.apple.com/kb/TS1292

  • How see the code of the application

    I would like to know how to see the code generated by APEX since I need to stamp(print) it.
    Thank you

    Hello,
    In FireFox : Right Mouse Click + View Page Source
    In IE: Right Mouse Click + View Source
    (might be a lot of pages though)
    Greetings,
    Roel
    http://roelhartman.blogspot.com/
    You can reward this reply by marking it as either Helpful or Correct ;-)

  • Where to see the code of enhanced field

    Hi experts,
    there is field called ZZEDATU , for 2LIS_12_VCITM i want to see the coding for it where do i see
    Thanks in Advance,
    Nitya

    Hi,
    Thanks for your answers, Resolved my problem
    Thnaks,
    Nitya

  • How can i see the code of SAP Exit for SAP Defined Variables

    Hi,
       It's very Urgent! How can i see the Source Code of SAP Provided Variables. I need to write code for User Defined Variables. please help me. It's very Urgent.
    Thanks in Advance.
    Nagesh.

    hi Nagesh,
    sample code for variable exit,
    there is 'how to' docs, can't see your email address.
      DATA: L_S_RANGE TYPE RSR_S_RANGESID.
      DATA: LOC_VAR_RANGE LIKE RRRANGEEXIT.
      CASE I_VNAM.
      WHEN 'CUMMONTH'.
        IF I_STEP = 2.                                  "after the popup
          LOOP AT I_T_VAR_RANGE INTO LOC_VAR_RANGE
                  WHERE VNAM = 'MONTH'.
            CLEAR L_S_RANGE.
            L_S_RANGE-LOW      = LOC_VAR_RANGE-LOW(4)."low value, e.g.200001
            L_S_RANGE-LOW+4(2) = '01'.
            L_S_RANGE-HIGH     = LOC_VAR_RANGE-LOW.   "high value = input
            L_S_RANGE-SIGN     = 'I'.
            L_S_RANGE-OPT      = 'BT'.
            APPEND L_S_RANGE TO E_T_RANGE.
            EXIT.
          ENDLOOP.
        ENDIF.
      ENDCASE.

  • HT204266 i cannot see the code on my gift card, what do i do?

    i bought an itunes gift card. my cousins were scratching it off and they did it too hard, now i cannot see the complete code, what can i do?

    Click here and request assistance. Include as much of the code as you can.
    (76918)

  • I pasted a line of code in my muse site google9cd204871dd4e782.html, is there any way to see the code so i can remove it?

    Hi, I pasted a line of code in my muse site, Is there any way to look at the code on my home page so i can remove this code? It is visible on my page when i view my site in browser, but i can't see it in muse.

    How did you paste the code? Did you insert HTML elerment? Or just paste it on the page? What's the site address?
    By the way. The code you have tried to add for Google webmaster tools should of been saved as a separate HTML file and upload it to your server to be verified, not put on the page, I think there are other methods that you put in the code to get  verified.
    thanks
    jason

  • I bought 2 app store cards and can not see the code on them

    i can not redeem my 2 $25 cards because i can't see the codes

    Invalid, inactive, or illegible codes
    http://support.apple.com/kb/TS1292

  • TS1292 i cant see the code on my itunes voucher how can i redeem it ?

    i cant see my voucher code how can u redeem the voucher?
    can any body help please?

    If you've scratched off the code and the page that you posted from doesn't help then you will need to try contacting iTunes support (you will need to give them as much of the serial number and activation code from the card as you can read) : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then iTunes Cards And Codes

  • I'd like to know how can see the code editor for FormBeans y ActionBean

    Hi, I'm testing JDeveloper 10 and found this problem: When a created (Struts) FormBeans or ActionBeans I can't see formBean class or where it created and obviusly can't see source code in code editor.
    Can you help me?
    Sorry for my english
    Paio

    Form beans will be created in the default package for the project. We don't create them for you automatically though - unless you click on an Action in the Diagram, and choose "Go to Form Bean" from the context menu.
    If you just create a bean in the Struts Structure pane - that will create the XML entry but not the implementation.

  • On my iTunes gift card I scratched to hard and I can't see the code, how can I still use the money on it?

    I got an iTunes gift card and when it said to scratch to reveal code, I must have scratched to hard and it scratched off the code. Is there anyway I can enter something somewhere and still get to use the gift card?

    You will have to contact iTunes support
    http://www.apple.com/support/itunes/contact.html

  • Is this a bug? come in to see the code please

    I am using Flex Builder 3 code name "Moxie".
    The basic idea is having a linkedbutton on a panel, then if
    you click on the linkedbutton, both the linkedbutton and the panel
    underneath catch the mouse click event. Is this a bug? I am
    expecting only the linkedbutton is able to capture the mouse click
    event. Or is there anything wrong with the codes? Thanks in advance
    for help.
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    layout="absolute" >
    <mx:Script>
    <![CDATA[
    import mx.controls.Alert;
    public function dpMouseDown(e:MouseEvent):void
    Alert.show("Mouse caught by PANEL");
    public function lkMouseDown(e:MouseEvent):void
    Alert.show("Mouse caught by LINKBUTTON");
    ]]>
    </mx:Script>
    <mx:Panel id="dPanel"
    height="100%" width="100%"
    borderStyle="none"
    backgroundColor="cyan"
    horizontalScrollPolicy = "off"
    verticalScrollPolicy = "off"
    click="dpMouseDown(event)"
    >
    <mx:LinkButton id="linkButton"
    label="HHHHHHHHHHHHHHHHHHHHHHHH"
    width="200" height="200" x="100" y="100"
    click="lkMouseDown(event)"/>
    </mx:Panel>
    </mx:Application>

    no its not a bug its the "bubbling" feature ( use the search
    to get more infos about the event handling)...
    If you replace the code in the function, you can stop the
    bubbling:
    public function lkMouseDown(e:MouseEvent):void
    Alert.show("Mouse caught by LINKBUTTON");
    e.stopImmediatePropagation();
    best regards,
    kcell

Maybe you are looking for