Create a clear button that will clear a jpanel

so i have two classes. One being a frame, and the other being a panel.
On the panel, i can draw various shapes with various colours etc. The frame contains the panel, and also a north panel containing various buttons to achieve this.
What i would i need to do is create a clear button that will clear the panel.
I know i can go and set it so it's draws a rectangle the same colour as the background but that would be cheating.
I will post a section of the paint just so you get an idea.
    public void paintComponent(Graphics gPanel) {
        if (this.buffer == null) {
            Dimension d = getSize();
            this.buffer = new BufferedImage(d.width, d.height,
                    BufferedImage.TYPE_INT_ARGB_PRE);
            myLineColour = new Color(0, 255, 0);     // initial colour for drawing
            this.g2Buffer = (Graphics2D) this.buffer.getGraphics();
            this.g2Buffer.setColor(Color.white);
            this.g2Buffer.fillRect(0, 0, d.width, d.height);
            // This time we'll draw with a broad pen 
        g2Buffer.setStroke(new BasicStroke(myLineWidth));
        if (myShapeFlag == 1){{
            this.g2Buffer.setColor(Color.white);
            g2Buffer.setXORMode(myLineColour); //go into the overwrite mode
            g2Buffer.drawLine(xStart, yStart, xOld, yOld); // undraw last
            g2Buffer.drawLine(xStart, yStart, xEnd, yEnd);     // draw new
            g2Buffer.setPaintMode();          // out of XOR overwrite mode
            xOld = xEnd;                    // store last end point
            yOld = yEnd;
        if(mouseReleased) {          // final time through
            g2Buffer.setColor(myLineColour);
            g2Buffer.drawLine(xStart, yStart, xEnd, yEnd);     // draw final
            mouseReleased = false;
        gPanel.drawImage(this.buffer, 0, 0, this); }Any help on this would be much appreciated

no idea how to do this.. sorry...
for the jbutton action listenener i'm not sure.
I think i'm on the right tracks with a method
    public void clearPanel(Graphics gPanel){
            g2Buffer.fillRect(100,100,100,100);     // draw final
            gPanel.drawImage(this.buffer, 0, 0, this);
}but again i think i'm way off the mark..

Similar Messages

  • How can I creat a control button that will allow the vi to run?

    Instead of pressing the run button, I want to creat my own run button that will allow my vi to run.
    Any idea?
    Thank you

    First you need to set the VI to Run When Opened (VI Properties>Execution). Then you create a front panel Boolean. On the diagram what you need to do is have some sort of idle state where nothing is done until the Boolean is pressed. It could be a separate while loop that doesn't exit until the Boolean is pressed, an Event Structure, or as part of a state machine. Look at the shippings examples Queued Message Handler, New Event Handler, Using Buttons for Options to name just a few.

  • I preordered an album and a song was released but it won't download. It just has a clear button that says "pre-ordered". How do I download the song but keep my pre-order for the rest of the album?

    I recently pre-ordered Ed Sheeran's "X Deluxe version" (or Multiply). He said he was releasing a song a day until the album was released. The most recent was Afire Love. The button where I should have "download" just has a clear button that says "pre-ordered". Shouldn't the song have already downloaded? How can I get the song without having to cancel my pre-order or getting charged for purchasing the song and the preorder?

    Hi kgiles13,
    It sounds like you may be having an issue with one of your purchases in the iTunes Store. Here is an article for you that will help you address this issue:
    Report an problem with an item you bought from the iTunes Store, App Store, Mac App Store, or iBooks Store
    http://support.apple.com/kb/ht1933
    Thanks for coming to the Apple Support Communities!
    Cheers,
    Braden

  • Can I create a button that will take me to a random slide in a sequence?

    Let's say I have three simulations setup and the simulations start on slide 5, 15, and 23. Can I make a button that will randomly jump to one of those slides?

    You have to execute that script using an event, in this case you'll use the Success event of the button that you created to 'jump'. And it will probably be an advanced action, unless you execute the JS with the On Enter event of the slide. You have two commands: first to execute the script, second to jump to that slide, for which you'll have to use a system variable cpCmndGotoSlide and the value of the variable returned by the JS. Slide numbering starts with index 0.
    http://blog.lilybiri.com/system-variables-in-captivate-6
    http://blog.lilybiri.com/events-and-advanced-actions
    Lilybiri

  • I need instructions on how to create a button that will email a pdf form to someone else on a websit

    I NEED ASSISTANCE CREATING A BUTTON THAT WILL EMAIL A PDF FORM FROM A WEBSITE TO WHOEVER THE VIEWER WANTS TO

    Just a bit more info. E-mail can be used, but has potential problems -- often related to the client machine that you have no control over. Use the data submissions (either FDF or XML) rather than the full PDF so you do not have to deal with Reader Rights and the related license issues. The FDF and XML data files are easily imported into the original form so that you see what the client sees. With those aspects in mind, just go ahead and try one. Be aware that you can add form fields using the form tools in the Advanced Editing tools, OR use the forms menu that will take you to Designer. You might want to try both to see the pros and cons. Be sure to keep such a test simple so you are not wasting time on your final form just for testing. I typically create a 1 page form that has all of the possible fields for such a test.

  • I am new at Captivate 8 and I have created a learning project using an existing power point presentation.  I have added a button that will allow my students to view a video on the subject.  When I run the project in Preview the button works but when I pub

    I am new at Captivate 8 and I have created a learning project using an existing power point presentation.  I have added a button that will allow my students to view a video on the subject.  When I run the project in Preview the button works but when I publish it, it stops working.

    I added an Interactions button and in the Actions on Success I open an URL or file. I have placed the video on our web server.   In the URL I point to our web server "http://www.wmabhs.org/Media/Add Client 3rd Party Coverage.mp4".  If I run this from any browser it works.  So what do you think I have done wrong?

  • Creating a button that will Copy my view from so I can paste it to MS Word

    Is there a way I can create a button that will copy my view from so I can paste it MS Word?
    I know I can select the entire form and copy and paste it, but is there a way to do it via a button similar to my "Print Form" button?
    Thank you.

    so there isn't a button that will copy the text my view form?
    instead of highlighting the data I want to easily copy it so I can paste it on a word document
    I came up with a script that when a item is highlighted I click the copy to clipboard and it copies the item.
    <script type="text/javascript">
    function CopyToClipboard()
    CopiedTxt = document.selection.createRange();
    CopiedTxt.execCommand("Copy");
    </script>
    but is there a way I can put in the script the area I want to start the copy from instead of highlighting the text first?
     

  • PL/SQL to create a temp table that will be dropped after session ends

    Is it possible in PL/SQL to create a temp table that will be dropped after the session ends? Please provide example if possible. I can create a global temp table in PL/SQL but I am not sure how (if possible) to have it 'drop' once the session ends.
    DB: 10g
    OS: Wiindoze 2003 Server
    :-)

    As others have mentioned (but probably not clearly explained), Oracle treats temporary tables differently to SQL Server.
    In SQL Server you create a temporary table and it gets dropped (automatically I assume, I dont do SQL Server) after the session finishes. This will obviously allow each session to "request" a temporary table to use, then use it, and not have to worry about cleaning up the database after the session has finished.
    Oracle takes a different approach...
    On the assumption that each session is likely to be creating a temporary table for the same purposes, with the same structure, Oracle let's you create a Global Temporary Table a.k.a. GTT (which you've already come across). You only have to create this table once and you leave it on the database. This then means that any code written to use that table doesn't have to be dynamic code and can be verified and checked at compile time, just like code written for any other table. The difference of a GTT from a regular table is that any data you put into that table can only be seen by that session and will not interfere with any data of other sessions and, when you either commit, or end the session (depending on the "on commit delete rows" or "on commit preserve rows" option used when creating the GTT), that data from your own session will automatically be removed and hence the table is cleaned up that way, whilst the actual table itself remains.
    Some people from SQL Server backgrounds try and create and drop tables dynamically in their PL/SQL code, but this leads to problems...
    SQL> ed
    Wrote file afiedt.buf
      1  begin
      2    execute immediate 'create table my_temp (x number)';
      3    insert into my_temp values (1);
      4    execute immediate 'drop table my_temp';
      5* end;
    SQL> /
      insert into my_temp values (1);
    ERROR at line 3:
    ORA-06550: line 3, column 15:
    PL/SQL: ORA-00942: table or view does not exist
    ORA-06550: line 3, column 3:
    PL/SQL: SQL Statement ignoredi.e. the code will not compile for direct DML statements trying to use that table.
    They then try and get around this issue by making their DML statements dynamic too...
    SQL> ed
    Wrote file afiedt.buf
      1  create or replace procedure my_proc is
      2  begin
      3    execute immediate 'create table my_temp (x number)';
      4    execute immediate 'insert into my_temp values (''A'')';
      5    execute immediate 'drop table my_temp';
      6* end;
    SQL> /
    Procedure created.... which looks great and it compiles ok... but... when they try and run it...
    SQL> exec my_proc;
    BEGIN my_proc; END;
    ERROR at line 1:
    ORA-01722: invalid number
    ORA-06512: at "SCOTT.MY_PROC", line 4
    ORA-06512: at line 1... oops the code has a bug in it. Our DML statement was invalid.
    This is really something that would have been caught at compile time, if the statement had been a direct DML statement rather than dynamic. And thus we see the problem with people trying to write all their code as dynamic SQL... it's more likely to contain bugs that won't be detected at compile time and only come to light at run time... sometimes only under certain conditions and sometimes once it's got into a production environment. Bad Idea!!!! ;)
    Far better to never create tables (or most other database objects) at run time. Just create them once as part of the database design/implementation and use them as required, allowing you to catch the most common coding errors up front before they get anywhere near a test environment or worse still, a production environment.

  • How can I create a submit button that only saves?

    Our end users will save the completed form and later upload it to anotherg place.  I created a save button that works fine, but without a Submit button there is nothing to trigger the reminder to go back and answer required questions.  I don't want to lose that part.  Thanks in advance for any help you can offfer!

    Would something like this work for you?
    var OKToSave = true;
    if (tfSomething.isNull) {
              tfSomething.border.edge.color.value = "255,0,0";
              OKToSave = false;
    else tfSomething.border.edge.color.value = "255,255,255";
    if (!OKToSave) app.alert("Please fill in all required fields");
    else app.execMenuItem("SaveAs");

  • How do you add a button that will email the PDF its on?

    I need to create a form but they want it to have a button that will open up an email to send that PDF as an attachment or something along those lines.  Is that possible?

    Just a bit more info. E-mail can be used, but has potential problems -- often related to the client machine that you have no control over. Use the data submissions (either FDF or XML) rather than the full PDF so you do not have to deal with Reader Rights and the related license issues. The FDF and XML data files are easily imported into the original form so that you see what the client sees. With those aspects in mind, just go ahead and try one. Be aware that you can add form fields using the form tools in the Advanced Editing tools, OR use the forms menu that will take you to Designer. You might want to try both to see the pros and cons. Be sure to keep such a test simple so you are not wasting time on your final form just for testing. I typically create a 1 page form that has all of the possible fields for such a test.

  • Is it possible to create a configuration profile that will install multiple network printers and their associated drivers

    Is it possible to create a configuration profile that will install multiple network printers and their associated drivers?
    I was not able to find profile manager on my employer's installation of 10.6 Server. Is this only a feature of 10.7/10.8 server?

    10.6 server does not have profile manager, profile manager is only available in 10/7 and 10.8 server
    for 10.6 server you'll need to use wgm and server admin
    printer management with 10.6, I recommend you read the relevant server manuals regarding
    print server and user management, printer management

  • 1. Firefox Help 2. Search Refine your search Found 0 results for I have a lot of firefox downloads BUT can't find anything to click to see them - Where is the button that will show all Firefox downloads? in English in English

    1. Firefox Help
    2. Search
    Refine your search
    Found 0 results for I have a lot of firefox downloads BUT can't find anything to click to see them - Where is the button that will show all Firefox downloads? in English in English

    Tools > Downloads or {Ctrl + J} will open the Downloads window

  • Will the AirPort Express Base Station create a wifi connection that will enable me to wirelessly connect to XBOX live on my xbox 360

    will the AirPort Express Base Station create a wifi connection that will enable me to wirelessly connect to XBOX live on my xbox 360

    Yes, but not in all cases with it provide your with an "Open NAT" condition that some on-line gaming require. However, for most Xbox LIVE access, it should work just fine.

  • I am trying to create an executable vi that will call out another vi and show its front panel in the executable​. When I try this I recieve this error message "top level vi (my main vi) was stopped at unknown on the block diagram of (my sub vi)

    I am trying to create an executable vi that will call out another vi and show its front panel in the executable.  When I try this I recieve this error message "top level vi (my main vi) was stopped at unknown on the block diagram of (my sub vi)

    Well the most common way is to enclude the vi's in the build spec either directly in the dependancies that the App builder automatically generates OR by declaring them in the build spec as "additional enclusions" (like you must do for dynamic vi calls in your app.
    I have heard rummors about My.app Stuff.vi in a nugget Intaris posted- and I've wanted to dig deaper into Intaris' claims- but have not tried it myself.
    If you go down the stuff.vi route Keep us curious guys posted
    Jeff

  • Can I add a button next to the location bar (just like the Home-button) that will open a new tab?

    In Firefox 3 there was a button that would open a new tab. This button was next to my location bar (next to the home, refresh, etc buttons), and also usable when I didn't have any tabs open (unlike the + on the tabbar, which is only there when I turn on my tabbar).
    Although there is a button I can add that will open a new window, I would like to know if it is possible to have similar button that will open a new tab.

    https://support.mozilla.com/en-US/kb/How+to+customize+the+toolbar
    There's a New Tab button in the Customize Palette, just move it to where you want it.

Maybe you are looking for