Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » General (non-technical) » Polish users » potrzebna pomoc
potrzebna pomoc [message #780546] Wed, 18 January 2012 14:53 Go to next message
adek admiral is currently offline adek admiralFriend
Messages: 2
Registered: January 2012
Junior Member
Po pierwsze witam wszystkich to mój pierwszy dzień na forum
Po drugie mam problem jestem początkujący i uczę się dopiero,korzystam z książki "Eclipse Biblioteka SWT" i nie mam pojęcia czemu nie chodzi mi jej z przykładów niżej podaje jego kod a pod spodem błędy wszystkim zainteresowanym z góry dziękuję za pomoc

package org.eclipseswt.r07.menu1;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;

public class Menu1Window {
private Display display;
private Shell shell;

private Canvas canvas;

static final int SHAPE_RECT = 0;
static final int SHAPE_CIRCLE = 1;
static final int COLOR_GREEN = 2;
static final int COLOR_BLUE = 3;

int shape = SHAPE_CIRCLE;
int color = COLOR_BLUE;

public Menu1Window() {
display = Display.getCurrent();
shell = new Shell(display);
init();
open();
startEventLoop();

}

public void open(){
shell.open();
}

public void startEventLoop() {
while(!shell.isDisposed()) {
if(!display.readAndDispatch()) display.sleep();
}
}

private void init(){
shell.setSize(400, 300);
shell.setText("Aplikacja Menu1");

canvas = new Canvas(shell, SWT.BORDER);
canvas.setBounds(0, 0, 200, 200);
canvas.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent event) {
GC gc = event.gc;
switch (color) {
case COLOR_GREEN:
gc.setBackground(display.getSystemColor(COLOR_GREEN));
break;
case COLOR_BLUE:
gc.setBackground(display.getSystemColor(COLOR_BLUE));
break;
}

switch (shape) {
case SHAPE_RECT:
gc.fillRectangle(10, 10, 180, 180);
break;
case SHAPE_CIRCLE:
gc.fillArc(10, 10, 180, 180, 0, 360);
break;
}
}


});

initMainMenu();
initPopupMenu();

}

private void initMainMenu() {
Menu menuBar = new Menu(shell, SWT.BAR);
shell.setMenu(menuBar);

MenuItem menuBarShapeItem = new MenuItem(menuBar, SWT.CASCADE);
menuBarShapeItem.setText("&Figura");

Menu submenuShape = new Menu(shell, SWT.DROP_DOWN);
menuBarShapeItem.setMenu(submenuShape);

MenuItem itemShapeRect = new MenuItem(submenuShape, SWT.PUSH);
itemShapeRect.setText("&Kwadrat");
itemShapeRect.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
shape = SHAPE_RECT;
canvas.redraw();
}

});

MenuItem itemShapeCircle = new MenuItem(submenuShape, SWT.PUSH);
itemShapeCircle.setText("K&oło");
itemShapeCircle.addListener(SWT.Selection, new Listener() {
public void handleEvent (Event e) {
shape = SHAPE_CIRCLE;
canvas.redraw();
}

});

MenuItem menuBarColorItem = new MenuItem(menuBar, SWT.CASCADE);
menuBarColorItem.setText("&Kolor");

Menu submenuColor = new Menu(shell, SWT.DROP_DOWN);
menuBarColorItem.setMenu(submenuColor);

MenuItem itemColorBlue = new MenuItem(submenuColor, SWT.PUSH);
itemColorBlue.setText("&Niebieski");
itemColorBlue.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
color = COLOR_BLUE;
canvas.redraw();
}

});

MenuItem itemColorGreen = new MenuItem(submenuColor, SWT.PUSH);
itemColorGreen.setText("&Zielony");
itemColorGreen.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
color = COLOR_GREEN;
canvas.redraw();
}
});

}

private void initPopupMenu() {
MenuItem item;

Menu popupMenu = new Menu(shell, SWT.POP_UP);

item = new MenuItem(popupMenu, SWT.PUSH);
item.setText("&Niebieski kwadrat");
item.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
color = COLOR_BLUE;
shape = SHAPE_RECT;
canvas.redraw();
}

});

item = new MenuItem(popupMenu, SWT.PUSH);
item.setText("&Zielony kwadrat");
item.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
color = COLOR_GREEN;
shape = SHAPE_RECT;
canvas.redraw();
}

});

item = new MenuItem(popupMenu, SWT.SEPARATOR);

item = new MenuItem(popupMenu, SWT.PUSH);
item.setText("Nie&bieskis koło");
item.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
color = COLOR_BLUE;
shape = SHAPE_CIRCLE;
canvas.redraw();
}

});

item = new MenuItem(popupMenu, SWT.PUSH);
item.setText("Zielone &koło");
item.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
color = COLOR_GREEN;
shape = SHAPE_CIRCLE;
canvas.redraw();
}

});

canvas.setMenu(popupMenu);

}
}

tutaj podaje błędy
Exception in thread "main" java.lang.IllegalArgumentException: Menu is not a POP_UP
at org.eclipse.swt.SWT.error(SWT.java:4263)
at org.eclipse.swt.SWT.error(SWT.java:4197)
at org.eclipse.swt.SWT.error(SWT.java:4168)
at org.eclipse.swt.widgets.Widget.error(Widget.java:468)
at org.eclipse.swt.widgets.Control.setMenu(Control.java:3459)
at org.eclipseswt.r07.menu1.Menu1Window.initMainMenu(Menu1Window.java:79)
at org.eclipseswt.r07.menu1.Menu1Window.init(Menu1Window.java:72)
at org.eclipseswt.r07.menu1.Menu1Window.<init>(Menu1Window.java:25)
at org.eclipseswt.r07.menu1.Menu1.main(Menu1.java:12)


Re: potrzebna pomoc [message #780554 is a reply to message #780546] Wed, 18 January 2012 15:32 Go to previous message
adek admiral is currently offline adek admiralFriend
Messages: 2
Registered: January 2012
Junior Member
jak przystało na początkującego błąd w składni

private void initMainMenu() {
Menu menuBar = new Menu(shell, SWT.BAR);
shell.setMenuBar(menuBar);

przepraszam za zaśmiecanie
Previous Topic:War file
Next Topic:Eclipse - linki w projekcie
Goto Forum:
  


Current Time: Tue Mar 19 06:53:45 GMT 2024

Powered by FUDForum. Page generated in 0.01894 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top