Event handling in scrollpane and graphics programming concept

I am still unclear about what to do to refresh a canvas inside a scrollpane?
what should i do with "repaint()" method of scrollpane??
clearly i have to update the drawing on the graphics g of the canvas, according to the viewport of the scrollpane so that a min. area is painted only.
will the "repaint()" method of canvas automatically get called when scrollbar is scrolled?? i tested but seems not.
do i have to consume adjustmentevent?? seems it's not a low level event
i saw in the console that the "update()" of the canvas sometimes get called twice when i scroll the scrollbar.
the problem i am having is : i got different effect when i clicked on different part of the scrollbar
clicked on the "bubble" will scroll the canvas, but once stopped the canvas that becomes visible(blank be4) is not updated
only clicking on the area next to the "bubble" will lead to a "great leap" and the screen get updated
i dont know how to override the adjustmentvaluechanged() actually

i clearrect() and drawline(), filloval() in the update() of canvas and call update() inside the paint() of the canvas, i dont know if i should make it this way
should i call repaint() of the scrollpane or repaint() of the canvas inside the adjustmentvaluechanged() of the scrollpane??

Similar Messages

  • Difference in event handling between Java and Java API

    could anyone list the differences between Java and java-API in event handling??
    thanks,
    cheers,
    Hiru

    the event handling mechanisms in java language
    features and API (java Application Programming
    Features)features .no library can work without a
    language and no language has event handling built in.
    I am trying to compare and contrast the event
    handling mechanisms in the language and library
    combinations such as java/ java API.
    all contributions are welcome!
    thanks
    cheersSorry, I'm still not getting it. I know what Java is, and I know what I think of when I hear API. (Application Programming Interface.) The API is the aggregation of all the classes and methods you can call in Java. If we agree on that, then the event handling mechanisms in Java and its API are one and the same.
    So what do you want to know?
    %

  • Event handling with UIScrollView and it's subview

    Hi,
    I have a UIScrollView and inside it a UIImageView. I have a lot of difficulities to handle the events with these two views. Here is what I want to do:
    If it is a multi-touch event (event.allTouches.count > 2), I want the UIScrollView to handle the event, i.e Zoom in/out and pan. If it a single touch event (event.allTouches.count == 1), I want the UIImageView to handle the event.
    Could you please tell me how to do this?
    Thank you very much.
    ff

    Take a look at the JSF Value-Changed Listener sections

  • Event handling with buttons and mouse

    Hi, Im a beginner in Java...!!!
    I have 4 buttons with me- 2 for color(red,blue) and 2 for size(big,small)..
    How do we divide the frame into 2 panels..one for Buttons and Other for Mouse events...
    Now,if I click on RED button and BIG button..and later click in the Mouse Panel area..I shud get a big rectangle filled with red color..and similarly for small / blue..etc...if a new selection is made..the previous rectangles should remain as they are...
    Im unable to get the implementation...any help will be appreciated.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    class ButtonPanel extends JPanel
    implements ActionListener, MouseMotionListener
    {  public ButtonPanel()
    blueButton = new JButton("Blue");
    redButton = new JButton("Red");
    bigButton = new JButton("Big");
    smallButton = new JButton("small");
    add(blueButton);
    add(redButton);
    add(bigButton);
    add(smallButton);
    blueButton.addActionListener(this);
    redButton.addActionListener(this);
    bigButton.addActionListener(this);
    smallButton.addActionListener(this);
    public void actionPerformed(ActionEvent evt)
    Color color = getBackground();
    repaint();
    // Paint Method
    public void paintComponent(Graphics g)
    {  super.paintComponent(g);
    class ButtonFrame extends JFrame
    {  public ButtonFrame()
    {  setTitle("ButtonTest");
    setSize(300, 200);
    addWindowListener(new WindowAdapter()
    {  public void windowClosing(WindowEvent e)
    {  System.exit(0);
    Container contentPane = getContentPane();
    contentPane.add(new ButtonPanel());
    public class ButtonTest
    {  public static void main(String[] args)
    {  JFrame frame = new ButtonFrame();
    frame.show();
    }

    can U kindly code it for me....!!!you're getting closer,
    http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=2&t=011033but rent-a-coder is that way ---->

  • Event handler of inbound plug not called when plug fired by event handler

    Hello All,
    I have a rather bizzare problem, hopefully someone out there can figure out what is going on, as I'm rather stumped.
    I have 2 views, A and B. They are linked by plugs, InA, InB, OutToA, OutToB. OutToB is linked to InB from A to B, OutToA is linked to InA from B to A.
    There is an onActionLink in view A. Clicking on this triggers an action which calls the wdFirePlugOutToB method.
    In view B some handling is done in the method onPlugInB, then wdFirePlugOutToA is called to change the displayed view back to A.
    As far as the user is concerned they don't ever see view B. (this bit works perfectly!)
    Now also in view A I have an event handler which handles a event from the component controller. It also calls wdFirePlugOutToB.
    If I trigger an event in the component controller this event handler is called and the method called. However, when I put a breakpoint in the onPlugInB, flow never reaches here. Flow does get to the wdDoModifyView of view B but never to the inbound plug event handler.
    Any suggestions as to what I might need to do? I would have thought calling the wdFirePlugOutToB method would ALWAYS trigger the linked event handler onPlugInB.
    I am running NW04 SP18.
    Thanks!

    Hi Bharathwaj,
    The project I'm working on has a requirement to allow for a road-mapped process (FPM) which has one step in which multiple screens can be accessed. I'll give an example: A user in step A selects the cost centre that they want to work with, in step B they need to maintain several pages of information about this cost centre. The do not want to break this information into steps, as there is no logical progression from one step to the next, and it may well be that the user wishes to go from maintaining screen 1 to screen 3, and then screen 2, and then screen 4. Stepping between all screens (1->2->3->2->3->4) wastes time and is not very user friendly. Step C of the process confirms the data that the user entered in step B, and Step D is the validation that the changes have been committed to the database. (a very familar 4 step process for those using ESS).
    To allow for this requirement, I have designed a left navigation pane type screen. links appear on the left of the screen and the user can use these to navigate between different screens (implemented as FPM IVAC VCs) on the right of the screen.
    It is quite an elegant solution (even if I do say so myself although quite complex to implement. I have relied very heavily on reading the code SAP put together for the FPM. The most complex part is that in order to update the the content of view containers in an application you must trigger a web dynpro view navigation by firing a plug to a different view.
    Unfortunately I don't have any sample application code, only the finished product, which I can't really share. But I can say that if you look at the FPM code carefully, working from where the wdInit of the FPM is called, it will eventually make sense.
    One thing I found slightly frustrating, you can't use the FPM's component usage register (FPM method attachComponentUsage(IWDComponent, IWDComponentUsage)) to add a VC... darned inconvienient really (you'd think that the web dynpro framework could have implemented the concept of extending an interface, but the IBLC and IVAC interfaces are different! - even though the IVAC is just IBLC + a few methods), but then again you can manage the instantiation of the used VC yourself and call the onInit method of the VC passing the current fpm reference, to attach it to a common FC, and given that you should be sharing context through the FC and never the VC, then really this isn't too much of an issue. (I spent ages worrying that I couldn't add the instances of the VC that I was using within my navigation pane VC to the fpm instance list, until I realised that it really didn't matter!)
    One day - when I have time (yeah right!) I might put together a blog about this sort of stuff, in the meantime, it keeps me plenty busy enough not to have the time!
    Hope this helped in some small way,
    Cheers,
    Chris

  • Event-handling mechanisms

    Hi All,
    I am looking for tutorials on the following and related topics:
    creating custom gui components that extend from JComponent
    event-handling mechanism STFWed and all I got was some examples on how to create them
    Look they give an idea on how to do it but that leaves me/you stranded
    in situations where you need to create one that is out of the scope of the example.
    + the examples don't always work.
    Links to preferably tutorials and even more examples would be much appreciated
    thanx
    gtRpr

    Sorry I thought I was in the New to Java Forum
    Only realized that I was in Java Programming Forum after I had created the Thread
    My Bad --- I will be more careful next time

  • Active Event handler in Web Survey SAP-BI.

    I am creating web survey in survey transaction. In change questionnaire section, when I insert event handler in the question for example TO POSTING the right mach code show u201CNO FUNCTION SELECTu201D.
    I need programming o check the input field value of the question. I load application library and assigning an application library to a Survey the implementation badi UWS_FORM_RUNTIME , how explicate Sap Library u2013 Web Survey http://help.sap.com/saphelp_nw04/helpdata/en/02/739fe7a80746caa668958d558993ae/frameset.htm, but not function.
    I have a question, As can I implement Exit, BADI, BTE  or other way for checking the value in input field the question in the questionnaire the web survey and active the event handler.
    Thanks and Regards
    Emely

    Hi Emily,
    did you solve the issue?
    I have exactly the same issue. I have created the class, I have assign the application library to the class via UBDS and the message appears with the error "no function selected".
    Could you give me any clue?
    Thanks, have a great weeknd.

  • OIM 11.1.1.5: Post Process Event Handler, change password notification

    Hi,
    Products
    OIM 11.1.1.5 BP02
    OAM 11.1.1.5
    OID 11.1.1.5
    Problem
    I have written a post-process event handler which fires when a role is assigned to a user. The event handler calls a plugin which uses the UserManager API to generate and change the user's password.
    I've tested this by assigning a role to the user via the OIM web console. I can see my log messages indicating that the event handler has fired and that the password has been changed.
    However, I expected that when UserManager.changePassword completed, a notification email would then be sent to the user informing them of the new password, but no notification email has been sent.
    The email notifications have been set up correctly, because I have changed the same user's password via the OIM web console and successfully received a Reset Password email.
    So, my questions are:
    1) Am I right in thinking that when you call UserManager.changePassword(), an out-of-the-box ResetPassword email notification should be sent to the user?
    2) Has anyone got this working in 11.1.1.5?
    Some more detailed info
    In my plugin class I'm calling the following from both execute methods (EventResult and BulkEventResult):
    char newpasswd[] = new RandomPasswordGeneratorImpl().generatePassword(user);
    getUserManager().changePassword(userKey, newpasswd, false, null, true);
    logger.info(("Successfully changed password"));
    plugin.xml
         <oimplugins xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
         <plugins pluginpoint="oracle.iam.platform.kernel.spi.EventHandler">
         <plugin
         pluginclass="oracle.iam.PostInsertPlugin"
         version="1.0"
         name="PostInsertPlugin">
         </plugin>
         </plugins>
         </oimplugins>
    $OIM_HOME/server/bin/weblogic.properties
              wls_servername = oim_server1
              app = OIMMetadata
              metadata_from_loc=/home/oracle/eventhandlers
              metadata_file=/metadata/roleuser/custom/EventHandlers.xml
    /home/oracle/eventhandlers/import/metadata/roleuser/custom/EventHandlers.xml
    <?xml version='1.0' encoding='utf-8'?>
    <eventhandlers
    xmlns="http://www.oracle.com/schema/oim/platform/kernel"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.oracle.com/schema/oim/platform/kernel orchestration-handlers.xsd">
    <action-handler
    class="oracle.iam.PostInsertPlugin"
    entity-type="RoleUser"
    operation="CREATE"
    name="PostInsertPlugin"
    stage="postprocess"
    order="1002"
    sync="TRUE"/>
    </eventhandlers>
    There are no errors in the OIM out and diagnostic logs apart from the following which occur at OIM startup:
    [2013-01-07T16:29:23.425+00:00] [oim_server1] [ERROR] [IAM-0080075] [oracle.iam.platform.kernel.impl] [tid: [ACTIVE].ExecuteThread: '13' for queue: 'weblogic.kernel.Default (self-tuning)'] [userId: oiminternal] [ecid: 2e903d7ef060ab65:66b2de91:13c15d6d9ce:-8000-0000000000000002,0] [APP: oim#11.1.1.3.0] XML schema validation failed for XML /metadata/iam-features-OIMMigration/EventHandlers.xml and it will not be loaded by kernel.
    [2013-01-07T16:29:24.267+00:00] [oim_server1] [ERROR] [IAM-0080075] [oracle.iam.platform.kernel.impl] [tid: [ACTIVE].ExecuteThread: '13' for queue: 'weblogic.kernel.Default (self-tuning)'] [userId: oiminternal] [ecid: 2e903d7ef060ab65:66b2de91:13c15d6d9ce:-8000-0000000000000002,0] [APP: oim#11.1.1.3.0] XML schema validation failed for XML /metadata/iam-features-callbacks/event_configuration/EventHandlers.xml and it will not be loaded by kernel.
    Thanks
    dty
    Edited by: oim_user on Jan 7, 2013 5:37 PM

    No notification will be sent if you changepassword using the method from usermanager api.
    You have to trigger the resetpassword event manullay in your code.
    Here is a sample code to create an event for reset password. Once you create event, invoke it from notification service - notify method.
    NotificationEvent event = new NotificationEvent();
    String[] receiverUserIds= {userLogin};
    event.setUserIds(receiverUserIds);
    event.setTemplateName("ResetPasswordNotification");
    event.setSender(null);
    HashMap<String, Object> resolvedData = new HashMap<String, Object>();
    resolvedData.put("userLoginId", userLogin);
    event.setParams(resolvedData);

  • Java and abap programing

    can any one help as in at freshers level how much of java programing is needed as in in details which all topics and where do u use later, i just know basics of abap.......
    Message was edited by: anu raj

    I think java will come in handy if you are developing Netweaver portals applications using Web dynpro java  or  jspdynpage applications.  In the latter, it is very important to know java very well.  With web dynpro, a lot of the coding is hidden from you, but you still need to know the basics of java and oo programming concepts.
    I noticed that you have already marked your post as "solved on my own".  I would suggest reversing that unitll your question has been answered completely.  When people see the blue star, then usually don't bother to read the post, hence limiting your answers.
    Once your question has been answered, award point accorindly.  Welcome to SDN!!
    Regards,
    Rich Heilman

  • SRM event handler creation

    Hi experts,
    we are trying to configure a questionnaire on the SRM.
    We would like to know if it is possible to put control on fields (example: field has to be numeric and of 5 digits. If the vendor writes only 4 digit the quastionnaire should not be sent). Is it possible to create a control by using event handler? How and where do I have to write the function?
    Thanks in advance,
    Regards,
    Riccardo

    Hi Chandra,
    when I have to deal with dependent values I normally do the following:
    Raise a Server Side Event in GET_P method as you did
    In the GET_V method I build up the value help and store it in a global variable on the context node. In the GET_V you have got access to the current entity with collection_wrapper->get_current() --> meaning you can always have the correct value of all the fields and read dependent on them.
    In the implementation class create an event handler that clears the global variable for the dependent value help whenever a new value is selected in the leading field.
    I suppose you have got a similar setup.
    One possibility to circumvent your problem is to skip the step with the global variable. Just shoot the server side event. This leads to a server roundtrip and the valuehelp for the dependent field is calculated again, based on the updated value of the leading field.
    However, this method is not very good for performance! Thus I would normally keep away from it.
    Concerning your problem with the wizard. It is correct that you have to have the view created with the wizard to be able to use it later on. On copied views the wizard does some redefinitions of common methods and it does complain if they are not exactly as it expects them.
    For event handlers I believe this should only be the DO_HANDLE_EVENT in the parent class of your IMPL. Meaning if you inherit from a SAP view inheritance is as follows:   SAP class --> SAP class _IMPL --> Your class --> Your class _IMPL
    The DO_HANDLE_EVENT would have to be in the Your class.
    An easy way would be recreating the view using the wizard (be sure to restart the component workbench after this).
    Another is create the event handler manually. Copy an existing EH_ONXXX method, and add a CASE statement into the DO_HANDLE_EVENT that calls this copied method.
    cheers Carsten

  • Event handler eats up memory. Bad programing and/or bug.

    Hello
    I've been programming a GUI for a project. The basics of the program is a sample routine that updates a array once a second. Once the array is updated I use a event handler to plot the new array in a graph.
    When I wrote this gui I think I've stumbled upon a bug in Labviews memory allocation.
    If you have two loops. One that builds a array and then signals a loop with a eventhandler that reads the array and the event handler is stoped for a few seconds (by opening a sub vi or something inside the event handler), the memory goes berserk. When the event handler is free after the stop the memory is still allocated and does not return.
    I could not find any information on this problem in the forum so I thought I would share this information with everyone. I managed to reproduce this phenomena in a small example (attached), if anyone is interested in it. The problem is simple to fix once you recognize the problem. However it was not the simplest problem to find (imho that is ).
    Regards
    Andreas Beckman
    Attachments:
    bug.zip ‏23 KB

    Where are you seeing the memory being allocated? What tool are you using, task manager or LabVIEW profiling? I'm not seeing what you describe (LV 7.1.1 on a 3.4 GHz Pentium 4 w/ 1 Gb memory)
    Thanks,
    Putnam
    Certified LabVIEW Developer
    Senior Test Engineer
    Currently using LV 6.1-LabVIEW 2012, RT8.5
    LabVIEW Champion

  • Test of Web Dynpro Event Handling : GeoMap business graphics

    Hy guru's, i have this problem: on Test of Web Dynpro Event Handling page i tried to open the GeoMap web dynpro on Business Graphics section but i received this error:
    The URL http://.../sap/bc/webdynpro/sap/wdr_test_events/ was not called due to an error.
    Note
    The following error text was processed in the system BI7 : Exception condition "COMMUNICATION_ERROR" raised.
    The error occurred on the application server bi7-saplab_BI7_08 and in the work process 0 .
    The termination type was: RABAX_STATE
    The ABAP call stack was:
    Method: IF_GIS_VIEW~UPDATE of program CL_GIS_VIEW_IGS===============CP
    Method: IF_WDR_VIEW_ELEMENT_ADAPTER~SET_CONTENT of program /1WDA/LBUSINESS_GRAPHICS======CP
    Method: IF_WDR_VIEW_ELEMENT_ADAPTER~SET_CONTENT of program /1WDA/L8STANDARD==============CP
    Method: IF_WDR_VIEW_ELEMENT_ADAPTER~SET_CONTENT of program /1WDA/L8STANDARD==============CP
    Method: IF_WDR_VIEW_ELEMENT_ADAPTER~SET_CONTENT of program /1WDA/L7STANDARD==============CP
    Method: IF_WDR_VIEW_ELEMENT_ADAPTER~SET_CONTENT of program /1WDA/L8STANDARD==============CP
    Method: IF_WDR_VIEW_ELEMENT_ADAPTER~SET_CONTENT of program /1WDA/L8STANDARD==============CP
    Method: IF_WDR_VIEW_ELEMENT_ADAPTER~SET_CONTENT of program /1WDA/L8STANDARD==============CP
    Method: IF_WDR_VIEW_ELEMENT_ADAPTER~SET_CONTENT of program /1WDA/L7STANDARD==============CP
    Method: IF_WDR_VIEW_ELEMENT_ADAPTER~SET_CONTENT of program /1WDA/L7STANDARD==============CP
    What can I do?
    If the termination type was RABAX_STATE, then you can find more information on the cause of the termination in the system BI7 in transaction ST22.
    If the termination type was ABORT_MESSAGE_STATE, then you can find more information on the cause of the termination on the application server bi7-saplab_BI7_08 in transaction SM21.
    If the termination type was ERROR_MESSAGE_STATE, then you can search for more information in the trace file for the work process 0 in transaction ST11 on the application server bi7-saplab_BI7_08 . In some situations, you may also need to analyze the trace files of other work processes.
    If you do not yet have a user ID, contact your system administrator.
    Error code: ICF-IE-http -c: 100 -u: AMARAVIGLIA -l: E -s: BI7 -i: bi7-saplab_BI7_08 -w: 0 -d: 20071119 -t: 232916 -v: RABAX_STATE -e: RAISE_EXCEPTION
    HTTP 500 - Internal Server Error
    Your SAP Internet Communication Framework Team
    Could you help me?
    Thank's a lot
    Sincerely yours
    Andrea Maraviglia

    Hi,
    did you install the IGS (see the <a href="http://help.sap.com/saphelp_nw70/helpdata/en/37/268841a79f1609e10000000a155106/frameset.htm">documentation</a>) and check if SAP note 1108034 helps?
    Regards, Heidi

  • How can I execute an external program from within a button's event handler?

    I am using Tomcat ApacheTomcat 6.0.16 with Netbeans 6.1 (with the latest JDK/J2EE)
    I need to execute external programs from an event handler for a button on a JSF page (the program is compiled, and extremely fast compared both to plain java and especially stored procedures written in SQL).
    I tried what I'd do in a standalone program (as shown in the appended code), but it didn't work. Instead I received text saying the program couldn't be found. This error message comes even if I try the Windows command "dir". I thought with 'dir' I'd at least get the contents of the current working directory. :-(
    I can probably get by with cgi on Apache's httpd server (or, I understand tomcat supports cgi, but I have yet to get that to work either), but whatever I do I need to be able to do it from within the button's event handler. And if I resort to cgi, I must be able to maintain session jumping from one server to the other and back.
    So, then, how can I do this?
    Thanks
    Ted
    NB: The programs that I need to run do NOT take input from the user. Rather, my code in the web application processes user selections from selection controls, and a couple field controls, sanitizes the inoputs and places clean, safe data in a MySQL database, and then the external program I need to run gets safe data from the database, does some heavy duty number crunching, and puts the output data into the database. They are well insulated from mischeif.
    NB: In the following array_function_test.pl was placed in the same folder as the web application's jsp pages, (and I'd tried WEB-INF - with the same result), and I DID see the file in the application's war file.
            try {
                java.lang.ProcessBuilder pn = new java.lang.ProcessBuilder("array_function_test.pl");
                //pn.directory(new java.io.File("K:\\work"));
                java.lang.Process pr = pn.start();
                java.io.BufferedInputStream bis = (java.io.BufferedInputStream)pr.getInputStream();
                String tmp = new String("");
                byte b[] = new byte[1000];
                int i = 0;
                while (i != -1) {
                    bis.read(b);
                    tmp += new String(b);
                getSelectionsDisplayTextArea().setText(getSelectionsDisplayTextArea().getText() + "\n\n" + tmp);
            } catch (java.io.IOException ex) {
                getSelectionsDisplayTextArea().setText(getSelectionsDisplayTextArea().getText() + "\n\n" + ex.getMessage());
            }

    Hi Fonsi!
    One way to execute an external program is to use the System Exec.vi. You find it in the functions pallet under Communication.
    /Thomas

  • Beginners Questions about Multiple JPanels in JFrame and event handling

    I am a newbie with SWING, and even a newerbie in Event Handling. So here goes.
    I am writing a maze program. I am placing a maze JPanel (MazePanel) at the center of a JFrame, and a JPanel of buttons (ButtonPanel) on the SOUTH pane. I want the buttons to be able to re-randomize the maze, solve the maze, and also ouput statistics (for percolation theory purposes). I have the backbone all done already, I am just creating the GUI now. I am just figuring out EventHandlers and such through the tutorials, but I have a question. I am adding an ActionListener to the buttons which are on the ButtonPanel which are on JFrame (SOUTH) Panel. But who do I make the ActionListener--Basically the one doing the work when the button is pressed. Do I make the JFrame the ActionListener or the MazePanel the ActionListener. I need something which has access to the maze data (the backbone), and which can call the Maze.randomize() function. I'm trying to make a good design and not just slop too.
    Also I was wondering if I do this
    JButton.addActionListener(MazePanel), and lets say public MazePanel implments ActionListenerdoesn't adding this whole big object to another object (namely the button actionlistener) seem really inefficient? And how does something that is nested in a JPanel on JFrame x get information from something nested in another JPanel on a JFrame x.
    Basically how is the Buttons going to talk to the maze when the maze is so far away?

    I'm not an expert, but here's what I'd do....
    You already have your business logic (the Maze classes), you said. I'm assuming you have some kind of public interface to this business logic. I would create a new class like "MazeGui" that extends JFrame, and then create the GUI using this class. Add buttons and panels as needed to get it to look the way you want. Then for each button that does a specific thing, add an anonymous ActionListener class to it and put whatever code you need inside the ActionListener that accesses the business logic classes and does what it needs to.
    This is the idea, though my code is totally unchecked and won't compile:
    import deadseasquirrels.mazestuff.*;
    public class MazeGui extends JFrame {
      JPanel buttonPanel = new JPanel();
      JPanel mazePanel = new JPanel();
      JButton randomizeB = new JButton();
      JButton solveB = new JButton();
      JButton statsB = new JButton();
      // create instanc(es) of your Maze business logic class(es)
      myMaze = new MazeClass();
      // add the components to the MazeGui content pane
      Component cp = getContentPane();
      cp.add(); // this doesn't do anything, but in your code you'd add
                // all of your components to the MazeGui's contentpane
      randomizeB.addActionListener(new ActionListener {
        void actionPerformed() {
          Maze newMaze = myMaze.getRandomMazeLayout();
          mazePanel.setContents(newMaze); // this is not a real method!
                                          // it's just to give you the idea
                                          // of how to manipulate the JPanel
                                          // representing your Maze diagram,
                                          // you will probably be changing a
                                          // subcomponent of the JPanel
      solveB.addActionListener(new ActionListener {
        void actionPerformed() {
          Solution mySolution = myMaze.getSolution();
          mazePanel.setContents(mySolution); // again, this is not a real
                                             // method but it shows you how
                                             // the ActionListener can
                                             // access your GUI
      // repeat with any other buttons you need
      public static void main(String[] args) {
        MazeGui mg = new MazeGui();
        mg.setVisible(true);
        // etc...
    }

  • Event Handling for Graphic Shapes

    Hi guys,
    I have a problem on the implementation of a piece of software that i'm making, to be more specific i implement a GUI. In this GUI i draw rectangles, lines and that kind of things.
    The problem is that i want when clicking on a rectangle, an event to take place such as the drawing of something else, or a message, etc.
    How am i to achieve that? I've tried many things but didn't succeeded it unfortunately. How am i going to "give" life to my rectangles by adding event handling for them? What code should i write?
    Note: My class extends JPanel & i'm using paint(Graphics g) for drawing the shapes
    Thanks,
    John.

    Try this:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.util.*;
    public class Shapes extends JFrame
         DPanel pan = new DPanel();
    public Shapes()
         addWindowListener(new WindowAdapter()
              public void windowClosing(WindowEvent ev)
                   dispose();
                   System.exit(0);
         setBounds(10,10,400,350); 
         setContentPane(pan);
         setVisible(true);
    public class DPanel extends JPanel implements MouseListener
         Vector shapes = new Vector();
         Shape  cs;
    public DPanel()
         addMouseListener(this);
         shapes.add(new Rectangle(20,20,100,40));
         shapes.add(new Rectangle(40,80,130,60));
         shapes.add(new Line2D.Double(20,150,200,180));
    public void paintComponent(Graphics g)
         super.paintComponent(g);
         Graphics2D g2 = (Graphics2D)g;
         for (int j=0; j < shapes.size(); j++)
              g2.draw((Shape)shapes.get(j));
         g.setColor(Color.red);
         if (cs != null) g2.draw(cs);
    public void mouseClicked(MouseEvent m) {}
    public void mouseEntered(MouseEvent m) {}
    public void mouseExited(MouseEvent m)  {}
    public void mouseReleased(MouseEvent m){}
    public void mousePressed(MouseEvent m)
         for (int j=0; j < shapes.size(); j++)
              Shape s = (Shape)shapes.get(j);
              Rectangle r = new Rectangle(m.getX()-1,m.getY()-1,2,2);
              if (s.intersects(r))
                   cs = s;
                   repaint();
    public static void main (String[] args) 
          new Shapes();
    }Noah

Maybe you are looking for

  • Should I overprint to avoid white space between colors when printing?

    Hello all,              I hope I don't get slammed for posting the wrong way! But I'll try. I print on a Summa DC4 thermal printer which prints one color at a time. I am using Illy CS4 with a cmyk document, all vectors. My Question is: Should I overp

  • Is it neccessary to have a universal adapter to connect my iPod to my audio system?

    Is it neccessary to have a universal adapter to connect my iPod to my audio system/iHome? If I connect it without one will it mess anything up?

  • Back up caused my phone to stop working...help!

    After trying to backup my iPhone 3G to Outlook as well as upgrading iTunes 8.2, I get an image on my phone with a plug, an arrow pointing to the iTunes logo. There is no phone service. Any suggestions?

  • External Hard Disk has become undetectable

    My WD external harddrive 500Gb use to show up on my computer, and is suddenly undetectable. It does however show up on the Disc Utility, but I can't verify or repair it. I have important video footage on the drive, and would like to retrieve it.....

  • JApplet on a browser

    I initially had a JFrame, I converted that to a JApplet and that runs fine on eclipse. When i try to run on a browser, I get the following error message Applet notinited.. this is my HTML code for the applet <html> <applet code = "StudentGUIApplet.cl