How can i impement some simple menu bar into this code ?

Hello all.
I have a problem with my program. I wanna add a simple menu bar, but i don't have any idea how to do it.
Here is code of my program:
import java.awt.Menu;
import javax.swing.event.MenuListener;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter.DEFAULT;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
public class SimpleGraphicEditor {
public Display display;
public Shell shell,shellmenu;
public Canvas canvas;
public Image imageBuffer;
org.eclipse.swt.widgets.Menu menu;
public Menu fileMenu, editMenu, viewMenu;
int startx=0;
int starty=0;
int endx=0;
int endy=0;
     public SimpleGraphicEditor() {
          display = new Display();
          shell = new Shell(display);
          createGUI();
          shell.open();
               while(!shell.isDisposed()) {
               if(!display.readAndDispatch()) {
                    display.sleep();
          } // end of simple grapphic editor
          private void createGUI() {
               shell.setLayout(new FillLayout());
               canvas = new Canvas(shell, SWT.BORDER);
               menu = null;
               shell.setText("Simple rec draw");
               shell.setSize(500, 500);
               shell.setMenuBar(menu);
               canvas.addPaintListener(new PaintListener() {
                         public void paintControl(PaintEvent e) {
                         e.gc.drawImage(imageBuffer, 0, 0, 500, 500, 0, 0, 500, 500);      
               imageBuffer = new Image(display, 500, 500);
               Listener listener = new Listener() {
                    private boolean isDrawing;
                    private GC gc = new GC(imageBuffer);
                    private int oldX = 0;
                    private int oldY = 0;
                    private int newX = 0;
                    private int newY = 0;
                    private boolean isDeleting;
                    public void handleEvent(Event event) {
                         // System.err.println("type=" + event.type);
                         switch(event.type) {
                         case SWT.MouseDown:
                              // System.err.println("button down");
                              switch(event.button) {
                              case 1:
                                   isDrawing = true;
                                   System.out.println("Start at:("+event.x+","+event.y);
                                   startx=event.x;
                                   starty=event.y;
                                   break;
                              case 2:
                                   System.err.println("button2 down");
                                   break;
                              case 3:
                                   isDeleting = true;
                                   gc.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
                                   break;
                              break;
                         case SWT.MouseUp:
                              // System.err.println("button up");
                              switch(event.button) {
                              case 1:
                                   isDrawing = false;
                                   // --- czyszczenie tablicy ---
                                   System.out.println("End at:("+event.x+","+event.y);
                                   int szerokosc=event.x-startx;
                                   int wysokosc=event.y-starty;
                                   //gc.drawRectangle(startx, starty, szerokosc,wysokosc);
                                   gc.setBackground(display.getSystemColor(SWT.COLOR_GREEN));
                                   gc.fillRectangle(startx, starty, szerokosc,wysokosc);
                                   canvas.redraw();
                                   break;
                              case 2:
                                   System.err.println("button2 up");
                                   break;
                              case 3:
                                   isDeleting = false;
                                   break;
                              break;
                         case SWT.MouseMove:
                              newX = event.x;
                              newY = event.y;
                              // System.err.println("mouse moved");
                              if(isDrawing) {
                                               // ----------- draw at hold  -----------------------------                    
                                   //gc.drawLine(oldX, oldY, newX, newY);
                                   int szerokosc=event.x-startx;
                                   int wysokosc=event.y-starty;
                                   gc.setForeground(display.getSystemColor(SWT.COLOR_BLACK));
                                   gc.drawText("x:"+event.x+", y:"+event.y+"  ", 0, 0);
                                   canvas.redraw();
                                   // ----- Clear the whole area -------------
                                   gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
                                   gc.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
                                   gc.fillRectangle(startx, starty, szerokosc+500, wysokosc+500);
                                   gc.fillRectangle(startx, starty, szerokosc-500, wysokosc-500);
                                   gc.fillRectangle(startx, starty, szerokosc+500, wysokosc-500);
                                   gc.fillRectangle(startx, starty, szerokosc-500, wysokosc+500);
                                   canvas.redraw();
                                   gc.setForeground(display.getSystemColor(SWT.COLOR_DARK_BLUE));
                                   gc.drawRectangle(startx, starty, szerokosc, wysokosc);
                                   canvas.redraw();
                                   int x = (oldX < newX) ? oldX : newX;
                                   int y = (oldY < newY) ? oldY : newY;
                                   int width = (oldX < newX) ? (newX-oldX) : (oldX - newX);
                                   int height = (oldY < newY) ? (newY-oldY) : (oldY - newY);
                                   if(width < 20) width = 20;
                                   if(height < 20) height = 20;
                                   canvas.redraw(x, y, width, height, true);
                              } else if(isDeleting) {
                                   // Color c = gc.getBackground();
                                   // gc.setBackground(gc.getForeground());
                                   gc.fillRectangle(newX - 15, newY - 15, 30, 30);
                                   canvas.redraw(newX - 15, newY - 15, 30, 30, true);
                                   // gc.setBackground(c);
                                   break;
                         } // end switch caly
                         oldX = event.x;
                         oldY = event.y;
               canvas.redraw();
               canvas.addListener(SWT.MouseDown, listener);
               canvas.addListener(SWT.MouseUp, listener);
               canvas.addListener(SWT.MouseMove, listener);
          public static void main(String[] args) {
               new SimpleGraphicEditor();
}

nitroduxe wrote:
ok i add the following code:
menu = new org.eclipse.swt.widgets.Menu(shell, SWT.BAR);
               MenuItem fileItem = new MenuItem(menu, SWT.CASCADE);
              fileItem.setText("menu1");
              MenuItem editItem = new MenuItem(menu, SWT.CASCADE);
              editItem.setText("menu2");
              MenuItem viewItem = new MenuItem(menu, SWT.CASCADE);
              viewItem.setText("menu3");
              shell.setMenuBar(menu); // DODANIE MENUhow now i can add some submenu into menu1 and menu2 and menu3 ?
Edited by: nitroduxe on Mar 9, 2010 10:23 AMI would start by reading the [menu tutorial|http://java.sun.com/docs/books/tutorial/uiswing/components/menu.html].

Similar Messages

  • HT3576 nt work. how can i my notification pull down bar doesfix this?

    my notification pull down bar does not work. how can i my notification pull down bar doesfix this?

    Norton says they are going to update 360 in April for the Firefox 4.0.
    You can get Firefox 3.6.16 here: <br />
    http://www.mozilla.com/en-US/firefox/all-older.html
    http://support.mozilla.com/en-US/kb/Installing+a+previous+version+of+Firefox

  • How can you create a spry menu bar with no background colour?

    How can you create the first level of a spry menu bar to have no colour? I have a coloured background right now and the colour matches when you load the site in Internet explorer but does not match in Firefox. Any suggestions are welcomed on how to fix this.
    Thanks!
    HK

    Here is the site:
    http://partnersnaturally.ca/
    I am learning with code, (obviously) so any feedback would be nice. I use dreamweaver CS4, but when I originally designed the site it was in a much older version of dreamweaver. I wonder if that could also be a cause. (besides human error)
    Thanks again,
    HK

  • How can I turn on the menu bar for veiw, help, bookmarks?

    I have lost the menu bar and status bar on my Firefox. How do I turn it back on?

    Firefox 3.6+ versions have a feature to allow the user to hide the Menu bar.
    Hit the '''Alt''' key to temporarily show the Menu bar, then open View > Toolbars and select Menu bar, so it has a check-mark. <br />
    The F10 can also be used on most PC's to temporarily reveal the Menu bar.
    https://support.mozilla.com/en-US/kb/Menu+bar+is+missing

  • How can i put on my menu bar spotlight ??

    at the begining spotlight was on the menu bar of desktop.. then after installation of lion osx the spotlight bar desappeared from the bar menu and now i can see only my login name

    It's a lot easier to use the keyboard shortcut which is Command - Spacebar.

  • How can I programmatically load a sub VI into my code

    Hi everybody,
    I am developing a program for an automated test system to determine the cut off frequency of  low pass filters.The filters in question are simulated in labview as sub VIs  with two inputs (input voltage and frequency) and one output (output voltage.
    I have already developed a program that can interrogate one filter and determine its cut off frequency.
    My challenge is how to test any of the filters automatically without writing parallel codes for all of them.
    Put in another way, I want the program to ask the user to load any of the filters (sub VI) from the desktop or from any other location so the the code I have already writing can interrogate the filters and determine the cut off frequency
    Any suggestion will be appreciated
    Thanks.
    kaydgreat.

    There are a couple of ways to do this, depending on your ability. You can do it with a heirarchy of inherited classes, or a selection of VIs with the same connector pane layout. (These are basically the same; classes would be more manageable, and selectable VIs probably quicker to implement)
    Search the example finder for 'plugin' to find a plug-in architecture of the latter of the above methods.
    - Cheers, Ed

  • I am working in the Develop module of Lightroom 5 and have accidentally bumped a setting and lost the Basic menu and the option to retrieve it.  "Tone curve" is directly under the tool bar now.  How can I retrieve the "Basic" menu?

    How can I retrieve the "Basic" menu on Lightroom 5?  I accidentally bumped something while working in the Develop module of Lightroom 5, and now the Tone Curve menu is directly under the Tool Bar, with no option to click on "Basic." 

    Right-click on Tone Curve and choose basic again or press Ctrl+1 in Develop.
    On Mac (Control-Click or Cmd+1)

  • After getting my software update for safari yesterday (version 6.0) I've lost the google search bar on my menu bar.  I've tried customizing the menu bar by dragging the google search bar to the menu bar, but no luck.  How can I get the google search bar b

    After getting my software update for safari yesterday (version 6.0) I've lost the google search bar on my menu bar.  I've tried customizing the menu bar by dragging the google search bar to the menu bar, but no luck.  How can I get the google search bar back?

    You can't. It's now integrated with the URL bar. It's a search/URL combo.

  • How can I access the help menu on the top bar? It tells me I am not connected or to try later.

    How can I access the help menu on the top bar? It tells me I am not connected or to try later.

    Is your Internet connection working? What application are you seeing this behavior in?

  • How do you make the Safari menu bars at the top and bottom of the browser go away in iOS7 when you can't scroll the screen?

    The menu bar at the bottom of Safari screens only goes away if you scroll the screen.  But for one page content, the screen can't be scrolled which renders useless any links/buttons at the bottom of the page.
    Is there a fix for this in iOS7?
    In iOS6, users needed only to tap the screen to remove the Safari menu bars.  This does not work in iOS6.

    In Safari > View choose Exit Full Screen

  • How do I delete items from menu bar  that are not part of the OS

    How do I delete items from menu bar  that are not part of the OS

    Perhaps you could be more specific, as it is a little difficult to answer your question without any details.  I can give you some general ideas though.
    On my machine there are a few applications that have installed items into the menu bar - I'm assuming you are talking about the icons on the right hand side of the top bar. To remove those items, I would generally need to uninstall the program that created them. To do this varies a little from application to application.
    Also, sometimes an application will have preferences that allow you choose if you want to display the item in the menu bar.
    So, my general advice would be that you need to identify the application that placed the item there, and remove it from your computer.  If there is an uninstall program for that application, I would run that in the first instance.
    If you don't actually wish to uninstall the application, you may need to click on the item or run the application and see if there is a setting to not show the menu bar item.
    Hope that helps.
    Ivan

  • Why can I not open pictures when I click on the host icon on my desktop? It just sits there, and can not open from top menu bar as well, only via itunes

    why can I not open pictures when I click on the host icon on my desktop? It just sits there, and can not open from top menu bar as well, only via itunes

    Does your question involve iPhoto in some way?

  • How can I down load msn tool bar for Mozilla firefox?

    My computer crashed and have lost msn tool bar. How can I down load msn tool bar for Mozilla firefox? edit

    It used to be more common to be asked how to uninstall such toolbars. I think It will now be known as a Bing bar, but as far as I know it is no longer supported for Firefox. You may find some unofficial addons with similar types of functions.
    You would be better discussing anything further relating to MSN on a specialist MSN forum.

  • Problem with simple menu bar

    Hi I'm making a simple menu bar but i have a little problem
    here. When i click the Productions button for the third time, it
    starts atthe top, in stead of the bottom. Can anyone figure out
    what's wrong?
    Thanks in Advace,
    Jordy

    your code is probably not what you want: your 2nd onPress
    handler will be invoked on the next button press after a button
    press (in which your first executes) AND your if-condition is
    satisfied. from then on, that's the only onPress handler that will
    execute (unless you have code elsewhere).

  • How can I shorten my dynamic menu?

    Hello World!
    Juste a simple question: How can I shorten my scroll-menu? (width) I can't shorten it! Does someone have a solution?
    Thanks a lot!

    Does someone can help me, please?
    Thanks

Maybe you are looking for

  • Report Server Misbehaviour

    Hi, We encountered a typical issue on our production AS box and would request your attention to understand this issue & its reason. The details are: Platform: Oracle9iAS R-2 9.0.2.3 on Windows-2000 SP-4 1. We have Oracle9i Reports deployed on Applica

  • Execute to Parse % is very low!!..need assistance

    HI, While looking in the statspack report, I found that under Instance efficiency area the percentage for 'Execute to parse' is 10.35% and rest of the percentage are as following: Buffer Nowait %: 99.89 Redo NoWait %: 100.00 Buffer Hit %: 92.57 In-me

  • Using icons as Jbuttons, how does the ActionListener distinquish this

    This may sound really simple, but I did search the forums, and also read up as much as I can find about the topic, but I haven't seen a solution. I am creating a button out of an image. I've sucessfully (except for a small annoyance, that I am still

  • CS4: Best use of SSD drives?

    I'm considering adding an SSD or two to the mix and am wondering where I'll get the best performance bang for the buck in a NLE situation. The current box is Vista, but I may be moving to faster ponies on a 64 bit 7 box soon. Doubt there's a differen

  • CNN won't connect with Safari

    I've had this problem for the last few months where cnn.com and m.cnn.com will not connect in Safari. I get the message "Safari could not load the page because the network connection was lost." This is the only website I've ever had this problem with