Painting in only one panel?

Hello,
I need to make a joystick style gui part in my applet, but only in one panel of the applet, Is it possible to paint in just one panel, and if so, can you point me in the right direction? Or even better, is there a joystick style swing component i dont know about? it basically just needs to be a slider with x and y components. Also, Would using a custom synth look and feel screw up any painting im trying to do? Thanks beforehand.
Cheers.

Andre_Uhres wrote:
I don't know about any "joystick style swing component" and I couldn't even tell you how to develop such a component.So I searched the web. This article might be helpful: [Virtual joystick GUI|http://www.freepatentsonline.com/6515687.html]. Logical Processing for the Virtual Joystick is summarized in the pseudo-code of TABLE 1.
Edited by: Andre_Uhres on Jan 30, 2010 11:35 AM
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SimpleJoystickDemo extends JFrame {
    private int displayWidth = 340;
    private int displayHeight = 550;
    private final Point position;
    public SimpleJoystickDemo() {
        super("SimpleJoystickDemo");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(displayWidth, displayHeight);
        setLocationRelativeTo(null);
        position = new Point();
        SimpleJoystick myJoystick = new SimpleJoystick(150, position, 100);
        add(myJoystick, BorderLayout.PAGE_END);
        Drawing drawing = new Drawing(position);
        add(drawing);
    public static void main(final String[] args) {
        Runnable gui = new Runnable() {
            public void run() {
                new SimpleJoystickDemo().setVisible(true);
        //GUI must start on EventDispatchThread:
        SwingUtilities.invokeLater(gui);
    class Drawing extends JPanel {
        private final Point position;
        public Drawing(Point position) {
            this.position = position;
        @Override
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D) g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                    RenderingHints.VALUE_ANTIALIAS_ON);
            g2.setColor(Color.RED);
            g2.fillOval(160 + position.x, 160 - position.y, 15, 15);
class SimpleJoystick extends JPanel {
    //Maximum value for full horiz or vert position where centered is 0:
    private int joyOutputRange;
    private float joySize;     //joystick icon size
    private float joyWidth, joyHeight;
    private float joyCenterX, joyCenterY;  //Joystick displayed Center
    //Display positions for text feedback values:
    private int textHorizPos, textVertPos;
    private int fontSpace = 12;
    private float curJoyAngle;    //Current joystick angle
    private float curJoySize;     //Current joystick size
    private boolean isMouseTracking;
    private boolean leftMouseButton;
    private int mouseX, mouseY;
    private Stroke lineStroke = new BasicStroke(10,
            BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
    private final Point position;
    public SimpleJoystick(final int joyOutputRange, final Point position,
            final int joySize) {
        this.joyOutputRange = joyOutputRange;
        this.position = position;
        this.joySize = joySize;
        joyWidth = joySize;
        joyHeight = joyWidth;
        setPreferredSize(new Dimension((int) joyWidth + 250,
                (int) joyHeight + 80));
        joyCenterX = getPreferredSize().width / 2;
        joyCenterY = getPreferredSize().height / 2;
        this.joySize = joyWidth / 2;
        setBackground(new Color(226, 226, 226));
        MouseAdapter mouseAdapter = new MouseAdapter() {
            @Override
            public void mouseMoved(final MouseEvent e) {
                mouseCheck(e);
            @Override
            public void mousePressed(final MouseEvent e) {
                leftMouseButton = SwingUtilities.isLeftMouseButton(e);
                mouseCheck(e);
        addMouseMotionListener(mouseAdapter);
        addMouseListener(mouseAdapter);
    private void mouseCheck(final MouseEvent e) {
        mouseX = e.getX();
        mouseY = e.getY();
        float dx = mouseX - joyCenterX;
        float dy = mouseY - joyCenterY;
        if (leftMouseButton) {
            isMouseTracking = true;
        } else {
            isMouseTracking = false;
        if (isMouseTracking) {
            curJoyAngle = (float) Math.atan2(dy, dx);
            curJoySize = (float) Point.distance(mouseX, mouseY,
                    joyCenterX, joyCenterY);
        } else {
            curJoySize = 0;
        if (curJoySize > joySize) {
            curJoySize = joySize;
        position.x = (int) (joyOutputRange * (Math.cos(curJoyAngle)
                * curJoySize) / joySize);
        position.y = (int) (joyOutputRange * (-(Math.sin(curJoyAngle)
                * curJoySize) / joySize));
        SwingUtilities.getRoot(SimpleJoystick.this).repaint();
    @Override
    protected void paintComponent(final Graphics g) {
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D) g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setColor(Color.LIGHT_GRAY);
        g2.fillOval((int) (joyCenterX - joyWidth / 2),
                (int) (joyCenterY - joyHeight / 2),
                (int) joyWidth, (int) joyHeight);
        //rotate and draw joystick line segment:
        Graphics2D g3 = (Graphics2D) g2.create();
        g3.translate(joyCenterX, joyCenterY);
        g3.rotate(curJoyAngle);
        g3.setColor(Color.GRAY);
        g3.setStroke(lineStroke);
        g3.drawLine(0, 0, (int) curJoySize, 0);
        g3.dispose();
        g2.setColor(Color.GRAY);
        g2.fillOval((int) joyCenterX - 10,
                (int) joyCenterY - 10, 20, 20);
        textHorizPos = 50;
        textVertPos = (int) (joyCenterY - 50);
        g2.drawString("Horiz:", textHorizPos, textVertPos);
        textHorizPos += (4 * fontSpace);
        g2.drawString(String.valueOf((int) position.x), textHorizPos,
                textVertPos);
        textHorizPos = 50;
        textVertPos += 12;
        g2.drawString("Vert:", textHorizPos, textVertPos);
        textHorizPos += (4 * fontSpace);
        g2.drawString(String.valueOf((int) position.y), textHorizPos,
                textVertPos);
}Edited by: Andre_Uhres on Feb 1, 2010 10:23 PM

Similar Messages

  • Dreamweaver Panels - Only one panel visible at a time, others get obscured even with Always On Top.

    I have a problem with my Dreamweaver MX, and it is that I can only see one panel at a time, any other open panels get obscured. For example, with the work space maximized, and having the properties and behaviors panels open, I can only see one of the panels at the same time. If I click on any area of the work space each open panel will display and with the next click the other will display. If I make the work space smaller then the whole area of my screen, and move any open panels outside of the Dreamweaver work space, only then they will stay visible. I know this is not normal behavior, because I used to be able to see all the open panels simultaneously, with the work space maximized to use all the screen area. I went to Preferences> Panels> Always On Top, and all the checkmarks are still set, so as to keep all panels on top at all times, but this does no longer be the case. Can someone tell me what happened here, and how I can get back to being able to see all the open panels? BTW, I tried installing older version of Dreamweaver 4, and the same thing happens to both installed versions. This is extremely annoying!
    Thanks. -Al.

    Since I upgraded to Firefox 19 from 18.0.2, on my Windows XP (SP3) laptop, I, too, can no longer open a new window. File-->New Window does nothing; also can no longer tear off a tab and open it in a new window (it stays where it is). Also, if I right-click on a tab and select Move to New Window, nothing happens. All of these worked fine in FF 18.0.2. All of these work fine with FF 19 on Windows 7. Only an issue on my XP laptop.
    After trying to open a new window, and not seeing the new window come up (and yes, I waited a long time), I decided to close my current window, which had multiple tabs open. Instead of just closing, it pops up the message reminding me that I'm about to close all those tabs. If I say close, and then go into the Task Manager, the Firefox application has disappeared (as expected), but the firefox (and plug-in container) processes are still running. So I have to manually kill the Firefox process to get it to quit. it's as if it thinks there is another Window open (the one I tried to open but never appeared). This happens every single time! I've restarted my laptop, and that does not resolve the problem.
    Is there a way to downgrade back to v 18.0.2 until this is fixed?

  • Why 1: Type selected in yellow and 2: only one panel stays open?

    In Design CS4. G5 Mac. Final Tiger.
    1. I was setting some type to be force justified L/R. Several lines of centered type. Most of it, not all of it, became selected in solid yellow. I did not do the selecting. I could not find the answer in either of two ID reference books.
    I checked the Prefs several times, and the only thing I found that MIGHT relate to this is "Keeps." (Preferences > Composition > Keeps Violations/H&J Violations.) Though it says nothing about color choice nor about what it signifies. I know what pink signifies, but not what yellow does.
    2. Asked about this next problem before and was told about Workspaces and was told about grouping panels, neither answering the question as I recall. So let me try again.
    I have panel A open. It may be alone as Panel A or in a group with Panel B and maybe even with Panel C. Doesn't matter. But now I want to open Panel D. As soon as I click on Panel D, Panel A (alone or grouped) disappears. So my question is: Can I/how can I keep more than one panel open at the same time, grouped or single being 100% irrelevant? How can I keep Panel A and Panel D open at the same time as separate, not grouped, panels?
    I tried to ask clearly. My experience is it is most efficient (in Adobe Forums and in real life) to be clear about what you do want and equally clear about what you do not.  —Thank you.

    1. Yellow highlight is, I believe, substituted glyphs. Is the affected type all caps or samll caps, perchance, or non-default figures? You usually see this with ligatures, but small caps is pretty common, too.
    2. Do you have auto-collapse panels selected inthe prefs? This one would help to see a screen shot, I think. If the panels are docked, you must expand the dock to panel width or only one group (and a group can be one panel) will expand from the icon state at a time.

  • How to drag a painted square from one panel to the other?

    Hi there,
    I'm a student IT, and for the course Programming, which uses Java, we have to write a game.
    I've got a JFrame with two JPanels. Both are overriding paint(Graphics g). One JPanel, let's say JP1, draws a board with 196 squares, the other, JP2, draws 21 pieces made up from the same size squares. What I want is, when I press on a piece in JP2, that I can drag that piece over to the board, JP1, and when I release the mousebutton, the piece is drawn in the board.
    How can I realize the dragging part? I've tried with an extra JPanel, with the size of the JFrame, but then either JP1, JP2, or both won't draw anymore.
    Can someone help me with this?
    Check here for a paint what I mean (don't mind my painting skills :p). At no.1, the mousebutton is pressed on the piece, at no. 2 the dragging starts, and at no. 3 the mousebutton is released again.
    Hope I've provided you enough information, I would post the source code here, but it's a lot in Dutch, and it may just confuse you ;)
    Greetings,
    Niek

    Ok, I'll study the link, and try to post my threads in the right section next time ;)
    Didn't even came up with me there might be a tutorial or something for this..
    Thank you! ;)
    Edited by: Niekfct on 17-mrt-2009 21:19

  • Why won't Painter erase a keyword on only ONE image at a time?

    This has been driving me crazy - I'd like to delete a keyword on select images. I have hundreds of keywords and many are nested, so sometimes I screw up and need to erase selectively. I thought this problem was a bug, but it has persisted into LR 2.4!
    In Grid mode, I select Painter, choose a keyword and search through images where the eraser icon shows. However, if I then click on that image, Lightroom sometimes erases that one image, but more commonly erases four or five at a time! (No, they aren't highlighted.)
    Any ideas? I'd sure appreciate them!
    Deb

    Thanks, Ian, but now I think it's a bug, not me. Occasionally, erasing with the Painter tool works fine, but more often it's truly a spray can out of control! I am using a tablet, not a mouse. Even if I highlight one image and then click quickly on the Painter, sometimes it will erase 3-6 additional images. I can't figure a rhyme or reason, except it seems more likely when I have hundreds of images showing.
    I had wondered if there was a way to set the Painter to only erase one image at a time. If I slide it over images (like spraying), it often is out of control.
    Thanks!

  • My CS6 Brush Tool does not sample - paints black only

    I have reset my tools individually and each tool.  Still the same - brush tool paints black only . 

    There's an odd little behaviour that can confuse, or down right drive you mad, where Alt (Opt) clicking the image with the Brush tool selected changes the 'Background' colour and not the Foreground colour.  To fix this open the Color Panel, and click on the Foreground colour, which will then become the 'active' colour and respond to Alt clicking a colour in the image.
    The difference is subtle.
    Foreground colour active
    Background colour active
    It will also depend on how you have your UI set.  With a dark UI I can see a thin white border around the active colour.  That changes to a black border with a lighter UI.  I found this one hard to track down when I first ran into it, so if new to you, commit it to memory.

  • I have just downloaded Elements 11 & there is only one frame (basic) in collage, how do I get more?

    I have just upgraded from Elements 7 to Elements 11 but find in the photo Collage there is only one frame, how do I get more, my old 7 had a good variety???

    Hi Wobygong5,
    I am afraid PSE11 has just one theme, ie. Basic.
    However you can go to Expert mode, and then create a new image of the size you want, and then insert frames from the Graphics panel. You can insert as many frames as you want.
    But Photo Collage will offer you just one theme.
    -Rahul.

  • Tint2: Multiple Desktops in one panel but spread over complete width

    Hi,
    I just installed Arch again und my desktop computer which has 2 monitors. I use tint2 as a panel and I have it on my secondary monitor only. I am using Openbox Multihead as Window Manager.
    Now I am able to get two distinct settings for tint2:
    - Showing the currently active desktop with all its windows at the default width
    - Showing all desktops where each desktop section receives the exact same space regardlass of active windows
    What I want: Showing all currently active windows like I had only one desktop (I am fine showing windows on desktop that are currently invisible) while having them spread out over the complete width.
    I know that the 'multi_desktop' option has the goal to be some kind of desktop pager where you can drag applications around. But my goal would be a view just like 'single_desktop' but with all currently opened windows.
    So I can see two possible solutions here:
    - Either tint2 can be configured in this way, or
    - I can trick tint2 by telling Openbox to always look at all desktops (at least if tint2 receives its information from the window manager)
    Is there any possibility to acheive my goal?
    Thanks in advance,
    javex

    It appears there is no solution out there but I did manage to find something else for myself:
    I now use only two desktops, each one is fixed to one monitor and through this, tint2 splits it in half which actually is pretty nice, since I can now switch around windows on monitors via taskbar.
    Should the need for more desktops arise, I will probably use some kind of composite cube or something which will provide the functionality, too.

  • Creating iphoto book and can't seem to view/ work on only one page at a time.

    I am creating an iPhoto book and can't seem to view/work on only one page at a time.  The Navigator, that allows you to focus on a part of the page is actually 1 1/2 pages in size so 1 1/2 pages are in view when trying to work on one page.  What am I doing wrong or how can I fix this.  It is very distracting viewing half of a previous page when trying to create a new page and write a story to go with the related pictures.

    My Navigator seems to be to large.  It covers 1 1/2 pages while in the training information it shows as the size of one page.  Is there a way to adjust the size of the Navigator?
    You can hover the mouse over the left border of the Navigator - then the cursor will turn into a resize cursor and you can drag the border and make the Navigator panel smaller by enlarging the source list.
    Or drag the lower right corner of the iPhoto window and shrink the appliaction window. This will only make the navigator smaller - the source list and information panel will stay the same size.
    Regards
    Léonie

  • Printing only one page problem

    Hi,
    I have a printable class that needs to print some text only on 1 page.
    The thing is that when I hit print the printer prints 3 pages:
    page 1 - with correct content
    page 2 - empty page
    page 3 - page with content translated some how
    then the printing stops.
    Here is the code:
    private static final double FACTOR = 2.83;
    private double width, height;
    private void setupJob(){
              // page width and height
              width = 75*FACTOR;
              height = 50*FACTOR;
              job = PrinterJob.getPrinterJob();          
              pf = new PageFormat();
              //PageFormat pf =job.pageDialog(job.defaultPage());
              aset = new HashPrintRequestAttributeSet();
              // Create a letter sized piece of paper with one inch margins
              paper = new Paper();
              // resize the paper and the imageable area
              paper.setSize(width, height);
              paper.setImageableArea(0, 0, width, height);
              // set paper for the pageFormat
              pf.setPaper(paper);
              // set the job printable by calling the painter of this object with the pf pageFormat
              job.setPrintable(this, pf);
              job.setCopies(1);          
              // set the media printable area in mm
              aset.add(new MediaPrintableArea( 0f, 0f, 75f, 50f, MediaPrintableArea.MM));          
              try {
                   job.print(aset);
              } catch (PrinterException e) {
                   e.printStackTrace();
    @Override
         public int print(Graphics g, PageFormat pf, int page)
                   throws PrinterException {     
              if (page > 0) { // We have only one page
                   return NO_SUCH_PAGE;
              }else{          
                   Graphics2D g2d = (Graphics2D)g;
                   // no translation needed
                   // g2d.translate(11.34f, 0);
                   // scale to fit page size
                   double sx = 0, sy = 0;
                   sx = width/(75*4);
                   sy = height/(50*4);
                   double scale = Math.min(sx, sy);
                   g2d.scale(scale,scale);
                   // draw the elements
                   for (int i=0; i<4; i++){
                        texts.drawText(g);
              return PAGE_EXISTS;
    Any help would be appreciated!
    Thanks!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Solved myself

  • Question about selecting only one tree at a time...Please help

    Hi , guys
    does anybody know how to make only one tree selected in an application which shows three trees simultaniously.
    Untill now I can select both trees at a time (the third one is not implemented yet ) This is probably so because the trees are showed in different panels I have no idea....Please give me some hints or ideas.
    I thank you in advance.

    write a TreeSelectionListener which knows all Trees in your application. add the listener to all three Trees. within the valueChanged method, check the events source to evaluate the tree, which fired the event. close all selections of all trees ( method clearSelection() ) except the one, which fired the event.
    regards,
    stefan

  • Have you chosen only one option button at a time

    Hi...
        I have got a problem while working with the option button in screen painter.I have three option buttons. In Run time, I want to select only one option button, mean while the other two option buttons should not be selected.
    ~
    Thank You in Advance
    Roseline Christina. B

    Hi,
    Please check the following
    To select an OptionBtn item, the item must be bound to a data source (UserDataSource or DBDataSource) using OptionBtn.DataBind
    The following is the sample to add 2 option buttons and group them.
    Dim optBtn As SAPbouiCOM.OptionBtn
        Dim oFrm As SAPbouiCOM.Form
        Dim oItem As SAPbouiCOM.Item
        Dim oUserdatasource As SAPbouiCOM.UserDataSource
        ' set oFrm = ..
        'Option 1
        Set oItem = oFrm.Items.Add("BD_rbRes", it_OPTION_BUTTON)
        oItem.Left = 240
        oItem.Top = 10
        oItem.Height = 16
        oItem.Width = 220
        Set optBtn = oItem.Specific
        optBtn.Caption = "Button One"
        Set oUserDataSource = oFrm.DataSources.UserDataSources.Add("BD_resDS", dt_SHORT_TEXT,1)
        optBtn.DataBind.SetBound True, , "BD_resDS"
        'Option 2
         Set oItem = oFrm.Items.Add("BD_rbPost", it_OPTION_BUTTON)
         oItem.Left = 240
         oItem.Top = 30
         oItem.Height = 16
         oItem.Width = 220
         Set optBtn = oItem.Specific
         optBtn.Caption = "Button Two"
         oItem.Visible = False
         Set optBtn = oItem.Specific
         optBtn.GroupWith ("BD_rbRes")
    Hope this helps,
    Vasu Natari.

  • Sound in only one ear of headset

    I get sound out of only one speaker of my headset.  (I have two headsets; same problem with both.  Yesterday I went into the control panel and reset the audio to the default setting.  That worked yesterday.  But when the same problem reappeared today, again I went back to the control panel and clicked on the reset-to-the-default setting, but this time nothing happened.  Any ideas? Thanks.

    Just clean the pop-port on your phone and the contacts on the headset.
    Use a cotton tip with a few drops of isopropyl alcohol on it but be careful not to bend the contacts on the headset.
    Was this post helpful? If so, please click on the white "Kudos!" star below. Thank you!

  • Flickering Image update (only one Image drawn on Component), 10+ Duke Dolla

    I've made an RBGFilter for Images and Combined it with a Thread
    to make an Image fade from Color to Grayscale.
    I use it together with an home made JComponent. It works, but the Image flickers.
    I've tried longer sleep periods (I thougt that maybe the filter was to slow) but it still flickered when changing the Image. I tried dubbel buffering, but couldn't get it to change the Image. Anyway, I suppose double buffering wouldn't help much, while it's only one Image to be drawn and it covers the entire Component.
    Does anyone have a clue about how to do?? You'll get plenty of Duke Dollars!
    (in the fade class)
    public void run()
    try{
    while( !Thread.interrupted() ){
    Thread.sleep( 70 );
    //Change colors:
    Image tmpImage = Toolkit.getDefaultToolkit().createImage(
    new FilteredImageSource( colorImage.getSource(), fadeFilter ) );
    ImageComponent.setImage( tmpImage ); //Home made component
    //test if fading is finished...
    catch( InterruptedException ie ){}
    (in the home made component)
    public void setImage( Image theImage )
    this.theImage = theImage;
    repaint();
    public void paintComponent( Graphics g )
    g.drawImage( theImage, 0, 0, this );
    }

    I dont know much about java but i do know a bit about MFC and this reminds me of a similiar issue in mfc. So heres my bet:
    Calls to repaint do call directly to paintComponent they first execute some code that paints the background of the component then calls the paintComponent routine. Typically the background is white and this results in flickering.
    Thats just a hunch. Because its similiar to an issue that you get in MFC around animation with framework paint calls.
    You can play the hunch by calling paintComponent directly and see if your flickering goes away. If it does find a way to use repaint without it repainting the background before it calls paintComponent (im sure theres a way or a similiar framework routine)
    One last thing? is the custom componet that your working with swing based? Cause swing based components are supposed to double buffer by default.

  • Only One domain controller, Remote Registry service keeps DISABLING itself. Where in the registry could this be set?

    This is killing my remote management. I have 4 server 2012R2 domain controllers.  Only one of them is being affected with this problem.  Almost everytime I check, the remote registry service is disabled again.  It seems like there is a corrupt
    group policy preference that keeps on attacking during a policy refresh, but I can't imagine setting a group policy to disable this service.  It is needed for our remote management.  Also the IP Tunnel service is also disabling.  Another strange
    artifact is that when I set a Windows Firewall policy to add an exception for remote administration in a group policy to my Admin workstation, it seemed to set a firewall rule in other computers to block remote administration.  I can not figure out where
    else this strange Windows Firewall rule Blocking remote administration could have come from.  These may be related or they may not, but they are occuring on the same domain controller.  I am able to set the RemoteRegistry service to enabled and to
    start it (which I have done too many times now), but it constantly is being changed back to disabled.  I am searching the registry to find any invalid entries or artifacts that may be affecting these two annoying effects, but I cannot find anything yet.
     Any ideas?  I need to know what policies will disable the remoteregistry service OR the IPTunelling service, or where in the registry this could be set to enact this during a policy refresh.  Of course, any other ideas are welcome, I have spent
    several days troubleshooting this, and need to conquer this by tomorrow if possible, thank you. James

    Hi,
    Please type
    services.msc in RUN to open Services panel, navigate to the Remote Registry service. Then open its Properties and set
    Startup type: Automatic. Then please check if this issue still exist.
    In addition, please refer to mlippold’s suggestion (the last reply) in following thread and configure relevant
    value in RemoteRegistry registry key, then check if can help you to solve this issue.
    For registry items, please back up all registry items before all operations. That will help us to avoid some unexpected issue.
    Remote
    Registry Service stops automatically if we do not use it above 10 minutes
    By the way, did you open Event Viewer and check if find any relevant errors?
    If any update, please feel free to let me know.
    Hope this helps.
    Best regards,
    Justin Gu
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Support, contact [email protected]

Maybe you are looking for