java.awt.Panel Usage, Examples, Demos and Tutorials

.Code Examples of java.awt.Panel is the simplest container class. A panel provides space in which an application can attach any other component, including other panels. The default layout manager for a panel is the FlowLayout layout manager. @version 1.37, 04/07/06 @author Sami Shaio @see java.awt.FlowLayout @since JDK1.0

myPlayerPoint = new PlayerPoint(aTeam, aUsername, 0, 0);

//init display parameters.

this.setSize(250,370);

this.setEnabled(false);

this.setResizable(false);

mainPanel = new Panel();

mainPanel.setSize(250, 300);

nItems=2; zoom=false;

// Get the image from the path and sets the size

URL imageUrl = LocalizerGUI.class.getResource(“vubZoomIn.png”);

Image backgroundImage = Toolkit.getDefaultToolkit().getImage(imageUrl.getPath());

imageCanvas = new ImageCanvas(backgroundImage);

imageCanvas.setBounds(mainPanel.getBounds());

imageCanvas.addMouseListener(this);

imageCanvas.addMouseMotionListener(this);

imageCanvas.setVisible(true);

mainPanel.add(imageCanvas,BorderLayout.CENTER);

virtualItems = new List();

virtualItems.setBounds(mainPanel.getBounds());

virtualItems.setBackground(Color.WHITE);

virtualItems.setMultipleMode(false);

virtualItems.setVisible(false);

mainPanel.add(virtualItems);

mainPanel.setVisible(true);

this.add(mainPanel,BorderLayout.CENTER);

//in the center of the frame

// Create the information container with the toolbar panel (downContentPanel)

Container downContentPanel = new Container();

downContentPanel.setLayout(new BorderLayout());

this.add(downContentPanel, BorderLayout.SOUTH); //in the south of the frame

msgBar = new Label(“”, Label.CENTER);

downContentPanel.add(msgBar, BorderLayout.CENTER);

Panel toolbarPanel = new Panel();

toolbarPanel.setLayout(new GridLayout(1,2));

ActionListener buttonListener = new ActionListener() {

public void actionPerformed(ActionEvent ae){

String action = ae.getActionCommand();

if (action.equals(LocalizerGUI.SHOW_ITEMS)) {

items.setLabel(LocalizerGUI.DISPOSE_ITEMS);

imageCanvas.setVisible(false);

virtualItems.setVisible(true);

pack();

} else if (action.equals(LocalizerGUI.DISPOSE_ITEMS)) {

items.setLabel(LocalizerGUI.SHOW_ITEMS);

virtualItems.setVisible(false);

imageCanvas.setVisible(true);

pack();

} else if (action.equals(LocalizerGUI.ZOOM_IN)){

zoom=true;

imageCanvas.repaint();

zoomIn.setEnabled(false);

zoomOut.setEnabled(true);

} else if (action.equals(LocalizerGUI.ZOOM_OUT)) {

zoom=false;

imageCanvas.repaint();

zoomIn.setEnabled(true);

zoomOut.setEnabled(false);

} else if (action.equals(LocalizerGUI.EXIT)) {

setVisible(false);

dispose();

System.exit(0);

}

};

};

Panel zoomPanel = new Panel();

zoomPanel.setLayout(new GridLayout(1,2));

zoomOut = new Button(LocalizerGUI.ZOOM_OUT);

zoomOut.addActionListener(buttonListener);

zoomOut.setEnabled(false);

zoomPanel.add(zoomOut);

zoomIn = new Button(LocalizerGUI.ZOOM_IN);

zoomIn.addActionListener(buttonListener);

zoomIn.setEnabled(false);

zoomPanel.add(zoomIn);

Button exit = new Button(LocalizerGUI.EXIT);

exit.addActionListener(buttonListener);

/*Panel rightToolbarPanel = new Panel();

rightToolbarPanel.setLayout(new GridLayout(1,2));

myPlayerPoint = new PlayerPoint(aTeam, aUsername, 0, 0);

//init display parameters.

this.setSize(250,370);

this.setEnabled(false);

this.setResizable(false);

mainPanel = new Panel();

mainPanel.setSize(250, 300);

nItems=2; zoom=false;

// Get the image from the path and sets the size

URL imageUrl = LocalizerGUI.class.getResource(“vubZoomIn.png”);

Image backgroundImage = Toolkit.getDefaultToolkit().getImage(imageUrl.getPath());

imageCanvas = new ImageCanvas(backgroundImage);

imageCanvas.setBounds(mainPanel.getBounds());

imageCanvas.addMouseListener(this);

imageCanvas.addMouseMotionListener(this);

imageCanvas.setVisible(true);

mainPanel.add(imageCanvas,BorderLayout.CENTER);

virtualItems = new List();

virtualItems.setBounds(mainPanel.getBounds());

virtualItems.setBackground(Color.WHITE);

virtualItems.setMultipleMode(false);

virtualItems.setVisible(false);

mainPanel.add(virtualItems);

mainPanel.setVisible(true);

this.add(mainPanel,BorderLayout.CENTER);

//in the center of the frame

// Create the information container with the toolbar panel (downContentPanel)

Container downContentPanel = new Container();

downContentPanel.setLayout(new BorderLayout());

this.add(downContentPanel, BorderLayout.SOUTH); //in the south of the frame

msgBar = new Label(“”, Label.CENTER);

downContentPanel.add(msgBar, BorderLayout.CENTER);

Panel toolbarPanel = new Panel();

toolbarPanel.setLayout(new GridLayout(1,2));

ActionListener buttonListener = new ActionListener() {

public void actionPerformed(ActionEvent ae){

String action = ae.getActionCommand();

if (action.equals(LocalizerGUI.SHOW_ITEMS)) {

items.setLabel(LocalizerGUI.DISPOSE_ITEMS);

imageCanvas.setVisible(false);

virtualItems.setVisible(true);

pack();

} else if (action.equals(LocalizerGUI.DISPOSE_ITEMS)) {

items.setLabel(LocalizerGUI.SHOW_ITEMS);

virtualItems.setVisible(false);

imageCanvas.setVisible(true);

pack();

} else if (action.equals(LocalizerGUI.ZOOM_IN)){

zoom=true;

imageCanvas.repaint();

zoomIn.setEnabled(false);

zoomOut.setEnabled(true);

} else if (action.equals(LocalizerGUI.ZOOM_OUT)) {

zoom=false;

imageCanvas.repaint();

zoomIn.setEnabled(true);

zoomOut.setEnabled(false);

} else if (action.equals(LocalizerGUI.EXIT)) {

setVisible(false);

dispose();

System.exit(0);

}

};

};

Panel zoomPanel = new Panel();

zoomPanel.setLayout(new GridLayout(1,2));

zoomOut = new Button(LocalizerGUI.ZOOM_OUT);

zoomOut.addActionListener(buttonListener);

zoomOut.setEnabled(false);

zoomPanel.add(zoomOut);

zoomIn = new Button(LocalizerGUI.ZOOM_IN);

zoomIn.addActionListener(buttonListener);

zoomIn.setEnabled(false);

zoomPanel.add(zoomIn);

Button exit = new Button(LocalizerGUI.EXIT);

exit.addActionListener(buttonListener);

/*Panel rightToolbarPanel = new Panel();

rightToolbarPanel.setLayout(new GridLayout(1,2));

myPlayerPoint = new PlayerPoint(aTeam, aUsername, 0, 0);

//init display parameters.

this.setSize(250,370);

this.setEnabled(false);

this.setResizable(false);

mainPanel = new Panel();

mainPanel.setSize(250, 300);

nItems=2; zoom=false;

// Get the image from the path and sets the size

URL imageUrl = LocalizerGUI.class.getResource(“vubZoomIn.png”);

Image backgroundImage = Toolkit.getDefaultToolkit().getImage(imageUrl.getPath());

imageCanvas = new ImageCanvas(backgroundImage);

imageCanvas.setBounds(mainPanel.getBounds());

imageCanvas.addMouseListener(this);

imageCanvas.addMouseMotionListener(this);

imageCanvas.setVisible(true);

mainPanel.add(imageCanvas,BorderLayout.CENTER);

virtualItems = new List();

virtualItems.setBounds(mainPanel.getBounds());

virtualItems.setBackground(Color.WHITE);

virtualItems.setMultipleMode(false);

virtualItems.setVisible(false);

mainPanel.add(virtualItems);

mainPanel.setVisible(true);

this.add(mainPanel,BorderLayout.CENTER);

//in the center of the frame

// Create the information container with the toolbar panel (downContentPanel)

Container downContentPanel = new Container();

downContentPanel.setLayout(new BorderLayout());

this.add(downContentPanel, BorderLayout.SOUTH); //in the south of the frame

msgBar = new Label(“”, Label.CENTER);

downContentPanel.add(msgBar, BorderLayout.CENTER);

Panel toolbarPanel = new Panel();

toolbarPanel.setLayout(new GridLayout(1,2));

ActionListener buttonListener = new ActionListener() {

public void actionPerformed(ActionEvent ae){

String action = ae.getActionCommand();

if (action.equals(LocalizerGUI.SHOW_ITEMS)) {

items.setLabel(LocalizerGUI.DISPOSE_ITEMS);

imageCanvas.setVisible(false);

virtualItems.setVisible(true);

pack();

} else if (action.equals(LocalizerGUI.DISPOSE_ITEMS)) {

items.setLabel(LocalizerGUI.SHOW_ITEMS);

virtualItems.setVisible(false);

imageCanvas.setVisible(true);

pack();

} else if (action.equals(LocalizerGUI.ZOOM_IN)){

zoom=true;

imageCanvas.repaint();

zoomIn.setEnabled(false);

zoomOut.setEnabled(true);

} else if (action.equals(LocalizerGUI.ZOOM_OUT)) {

zoom=false;

imageCanvas.repaint();

zoomIn.setEnabled(true);

zoomOut.setEnabled(false);

} else if (action.equals(LocalizerGUI.EXIT)) {

setVisible(false);

dispose();

System.exit(0);

}

};

};

Panel zoomPanel = new Panel();

zoomPanel.setLayout(new GridLayout(1,2));

zoomOut = new Button(LocalizerGUI.ZOOM_OUT);

zoomOut.addActionListener(buttonListener);

zoomOut.setEnabled(false);

zoomPanel.add(zoomOut);

zoomIn = new Button(LocalizerGUI.ZOOM_IN);

zoomIn.addActionListener(buttonListener);

zoomIn.setEnabled(false);

zoomPanel.add(zoomIn);

Button exit = new Button(LocalizerGUI.EXIT);

exit.addActionListener(buttonListener);

/*Panel rightToolbarPanel = new Panel();

rightToolbarPanel.setLayout(new GridLayout(1,2));

myPlayerPoint = new PlayerPoint(aTeam, aUsername, 0, 0);

//init display parameters.

this.setSize(250,370);

this.setEnabled(false);

this.setResizable(false);

mainPanel = new Panel();

mainPanel.setSize(250, 300);

nItems=2; zoom=false;

// Get the image from the path and sets the size

URL imageUrl = LocalizerGUI.class.getResource(“vubZoomIn.png”);

Image backgroundImage = Toolkit.getDefaultToolkit().getImage(imageUrl.getPath());

imageCanvas = new ImageCanvas(backgroundImage);

imageCanvas.setBounds(mainPanel.getBounds());

imageCanvas.addMouseListener(this);

imageCanvas.addMouseMotionListener(this);

imageCanvas.setVisible(true);

mainPanel.add(imageCanvas,BorderLayout.CENTER);

virtualItems = new List();

virtualItems.setBounds(mainPanel.getBounds());

virtualItems.setBackground(Color.WHITE);

virtualItems.setMultipleMode(false);

virtualItems.setVisible(false);

mainPanel.add(virtualItems);

mainPanel.setVisible(true);

this.add(mainPanel,BorderLayout.CENTER);

//in the center of the frame

// Create the information container with the toolbar panel (downContentPanel)

Container downContentPanel = new Container();

downContentPanel.setLayout(new BorderLayout());

this.add(downContentPanel, BorderLayout.SOUTH); //in the south of the frame

msgBar = new Label(“”, Label.CENTER);

downContentPanel.add(msgBar, BorderLayout.CENTER);

Panel toolbarPanel = new Panel();

toolbarPanel.setLayout(new GridLayout(1,2));

ActionListener buttonListener = new ActionListener() {

public void actionPerformed(ActionEvent ae){

String action = ae.getActionCommand();

if (action.equals(LocalizerGUI.SHOW_ITEMS)) {

items.setLabel(LocalizerGUI.DISPOSE_ITEMS);

imageCanvas.setVisible(false);

virtualItems.setVisible(true);

pack();

} else if (action.equals(LocalizerGUI.DISPOSE_ITEMS)) {

items.setLabel(LocalizerGUI.SHOW_ITEMS);

virtualItems.setVisible(false);

imageCanvas.setVisible(true);

pack();

} else if (action.equals(LocalizerGUI.ZOOM_IN)){

zoom=true;

imageCanvas.repaint();

zoomIn.setEnabled(false);

zoomOut.setEnabled(true);

} else if (action.equals(LocalizerGUI.ZOOM_OUT)) {

zoom=false;

imageCanvas.repaint();

zoomIn.setEnabled(true);

zoomOut.setEnabled(false);

} else if (action.equals(LocalizerGUI.EXIT)) {

setVisible(false);

dispose();

System.exit(0);

}

};

};

Panel zoomPanel = new Panel();

zoomPanel.setLayout(new GridLayout(1,2));

zoomOut = new Button(LocalizerGUI.ZOOM_OUT);

zoomOut.addActionListener(buttonListener);

zoomOut.setEnabled(false);

zoomPanel.add(zoomOut);

zoomIn = new Button(LocalizerGUI.ZOOM_IN);

zoomIn.addActionListener(buttonListener);

zoomIn.setEnabled(false);

zoomPanel.add(zoomIn);

Button exit = new Button(LocalizerGUI.EXIT);

exit.addActionListener(buttonListener);

/*Panel rightToolbarPanel = new Panel();

rightToolbarPanel.setLayout(new GridLayout(1,2));

myPlayerPoint = new PlayerPoint(aTeam, aUsername, 0, 0);

//init display parameters.

this.setSize(250,370);

this.setEnabled(false);

this.setResizable(false);

mainPanel = new Panel();

mainPanel.setSize(250, 300);

nItems=2; zoom=false;

// Get the image from the path and sets the size

URL imageUrl = LocalizerGUI.class.getResource(“vubZoomIn.png”);

Image backgroundImage = Toolkit.getDefaultToolkit().getImage(imageUrl.getPath());

imageCanvas = new ImageCanvas(backgroundImage);

imageCanvas.setBounds(mainPanel.getBounds());

imageCanvas.addMouseListener(this);

imageCanvas.addMouseMotionListener(this);

imageCanvas.setVisible(true);

mainPanel.add(imageCanvas,BorderLayout.CENTER);

virtualItems = new List();

virtualItems.setBounds(mainPanel.getBounds());

virtualItems.setBackground(Color.WHITE);

virtualItems.setMultipleMode(false);

virtualItems.setVisible(false);

mainPanel.add(virtualItems);

mainPanel.setVisible(true);

this.add(mainPanel,BorderLayout.CENTER);

//in the center of the frame

// Create the information container with the toolbar panel (downContentPanel)

Container downContentPanel = new Container();

downContentPanel.setLayout(new BorderLayout());

this.add(downContentPanel, BorderLayout.SOUTH); //in the south of the frame

msgBar = new Label(“”, Label.CENTER);

downContentPanel.add(msgBar, BorderLayout.CENTER);

Panel toolbarPanel = new Panel();

toolbarPanel.setLayout(new GridLayout(1,2));

ActionListener buttonListener = new ActionListener() {

public void actionPerformed(ActionEvent ae){

String action = ae.getActionCommand();

if (action.equals(LocalizerGUI.SHOW_ITEMS)) {

items.setLabel(LocalizerGUI.DISPOSE_ITEMS);

imageCanvas.setVisible(false);

virtualItems.setVisible(true);

pack();

} else if (action.equals(LocalizerGUI.DISPOSE_ITEMS)) {

items.setLabel(LocalizerGUI.SHOW_ITEMS);

virtualItems.setVisible(false);

imageCanvas.setVisible(true);

pack();

} else if (action.equals(LocalizerGUI.ZOOM_IN)){

zoom=true;

imageCanvas.repaint();

zoomIn.setEnabled(false);

zoomOut.setEnabled(true);

} else if (action.equals(LocalizerGUI.ZOOM_OUT)) {

zoom=false;

imageCanvas.repaint();

zoomIn.setEnabled(true);

zoomOut.setEnabled(false);

} else if (action.equals(LocalizerGUI.EXIT)) {

setVisible(false);

dispose();

System.exit(0);

}

};

};

Panel zoomPanel = new Panel();

zoomPanel.setLayout(new GridLayout(1,2));

zoomOut = new Button(LocalizerGUI.ZOOM_OUT);

zoomOut.addActionListener(buttonListener);

zoomOut.setEnabled(false);

zoomPanel.add(zoomOut);

zoomIn = new Button(LocalizerGUI.ZOOM_IN);

zoomIn.addActionListener(buttonListener);

zoomIn.setEnabled(false);

zoomPanel.add(zoomIn);

Button exit = new Button(LocalizerGUI.EXIT);

exit.addActionListener(buttonListener);

/*Panel rightToolbarPanel = new Panel();

rightToolbarPanel.setLayout(new GridLayout(1,2));

myPlayerPoint = new PlayerPoint(aTeam, aUsername, 0, 0);

//init display parameters.

this.setSize(250,370);

this.setEnabled(false);

this.setResizable(false);

mainPanel = new Panel();

mainPanel.setSize(250, 300);

nItems=2; zoom=false;

// Get the image from the path and sets the size

URL imageUrl = LocalizerGUI.class.getResource(“vubZoomIn.png”);

Image backgroundImage = Toolkit.getDefaultToolkit().getImage(imageUrl.getPath());

imageCanvas = new ImageCanvas(backgroundImage);

imageCanvas.setBounds(mainPanel.getBounds());

imageCanvas.addMouseListener(this);

imageCanvas.addMouseMotionListener(this);

imageCanvas.setVisible(true);

mainPanel.add(imageCanvas,BorderLayout.CENTER);

virtualItems = new List();

virtualItems.setBounds(mainPanel.getBounds());

virtualItems.setBackground(Color.WHITE);

virtualItems.setMultipleMode(false);

virtualItems.setVisible(false);

mainPanel.add(virtualItems);

mainPanel.setVisible(true);

this.add(mainPanel,BorderLayout.CENTER);

//in the center of the frame

// Create the information container with the toolbar panel (downContentPanel)

Container downContentPanel = new Container();

downContentPanel.setLayout(new BorderLayout());

this.add(downContentPanel, BorderLayout.SOUTH); //in the south of the frame

msgBar = new Label(“”, Label.CENTER);

downContentPanel.add(msgBar, BorderLayout.CENTER);

Panel toolbarPanel = new Panel();

toolbarPanel.setLayout(new GridLayout(1,2));

ActionListener buttonListener = new ActionListener() {

public void actionPerformed(ActionEvent ae){

String action = ae.getActionCommand();

if (action.equals(LocalizerGUI.SHOW_ITEMS)) {

items.setLabel(LocalizerGUI.DISPOSE_ITEMS);

imageCanvas.setVisible(false);

virtualItems.setVisible(true);

pack();

} else if (action.equals(LocalizerGUI.DISPOSE_ITEMS)) {

items.setLabel(LocalizerGUI.SHOW_ITEMS);

virtualItems.setVisible(false);

imageCanvas.setVisible(true);

pack();

} else if (action.equals(LocalizerGUI.ZOOM_IN)){

zoom=true;

imageCanvas.repaint();

zoomIn.setEnabled(false);

zoomOut.setEnabled(true);

} else if (action.equals(LocalizerGUI.ZOOM_OUT)) {

zoom=false;

imageCanvas.repaint();

zoomIn.setEnabled(true);

zoomOut.setEnabled(false);

} else if (action.equals(LocalizerGUI.EXIT)) {

setVisible(false);

dispose();

System.exit(0);

}

};

};

Panel zoomPanel = new Panel();

zoomPanel.setLayout(new GridLayout(1,2));

zoomOut = new Button(LocalizerGUI.ZOOM_OUT);

zoomOut.addActionListener(buttonListener);

zoomOut.setEnabled(false);

zoomPanel.add(zoomOut);

zoomIn = new Button(LocalizerGUI.ZOOM_IN);

zoomIn.addActionListener(buttonListener);

zoomIn.setEnabled(false);

zoomPanel.add(zoomIn);

Button exit = new Button(LocalizerGUI.EXIT);

exit.addActionListener(buttonListener);

/*Panel rightToolbarPanel = new Panel();

rightToolbarPanel.setLayout(new GridLayout(1,2));

myPlayerPoint = new PlayerPoint(aTeam, aUsername, 0, 0);

//init display parameters.

this.setSize(250,370);

this.setEnabled(false);

this.setResizable(false);

mainPanel = new Panel();

mainPanel.setSize(250, 300);

nItems=2; zoom=false;

// Get the image from the path and sets the size

URL imageUrl = LocalizerGUI.class.getResource(“vubZoomIn.png”);

Image backgroundImage = Toolkit.getDefaultToolkit().getImage(imageUrl.getPath());

imageCanvas = new ImageCanvas(backgroundImage);

imageCanvas.setBounds(mainPanel.getBounds());

imageCanvas.addMouseListener(this);

imageCanvas.addMouseMotionListener(this);

imageCanvas.setVisible(true);

mainPanel.add(imageCanvas,BorderLayout.CENTER);

virtualItems = new List();

virtualItems.setBounds(mainPanel.getBounds());

virtualItems.setBackground(Color.WHITE);

virtualItems.setMultipleMode(false);

virtualItems.setVisible(false);

mainPanel.add(virtualItems);

mainPanel.setVisible(true);

this.add(mainPanel,BorderLayout.CENTER);

//in the center of the frame

// Create the information container with the toolbar panel (downContentPanel)

Container downContentPanel = new Container();

downContentPanel.setLayout(new BorderLayout());

this.add(downContentPanel, BorderLayout.SOUTH); //in the south of the frame

msgBar = new Label(“”, Label.CENTER);

downContentPanel.add(msgBar, BorderLayout.CENTER);

Panel toolbarPanel = new Panel();

toolbarPanel.setLayout(new GridLayout(1,2));

ActionListener buttonListener = new ActionListener() {

public void actionPerformed(ActionEvent ae){

String action = ae.getActionCommand();

if (action.equals(LocalizerGUI.SHOW_ITEMS)) {

items.setLabel(LocalizerGUI.DISPOSE_ITEMS);

imageCanvas.setVisible(false);

virtualItems.setVisible(true);

pack();

} else if (action.equals(LocalizerGUI.DISPOSE_ITEMS)) {

items.setLabel(LocalizerGUI.SHOW_ITEMS);

virtualItems.setVisible(false);

imageCanvas.setVisible(true);

pack();

} else if (action.equals(LocalizerGUI.ZOOM_IN)){

zoom=true;

imageCanvas.repaint();

zoomIn.setEnabled(false);

zoomOut.setEnabled(true);

} else if (action.equals(LocalizerGUI.ZOOM_OUT)) {

zoom=false;

imageCanvas.repaint();

zoomIn.setEnabled(true);

zoomOut.setEnabled(false);

} else if (action.equals(LocalizerGUI.EXIT)) {

setVisible(false);

dispose();

System.exit(0);

}

};

};

Panel zoomPanel = new Panel();

zoomPanel.setLayout(new GridLayout(1,2));

zoomOut = new Button(LocalizerGUI.ZOOM_OUT);

zoomOut.addActionListener(buttonListener);

zoomOut.setEnabled(false);

zoomPanel.add(zoomOut);

zoomIn = new Button(LocalizerGUI.ZOOM_IN);

zoomIn.addActionListener(buttonListener);

zoomIn.setEnabled(false);

zoomPanel.add(zoomIn);

Button exit = new Button(LocalizerGUI.EXIT);

exit.addActionListener(buttonListener);

/*Panel rightToolbarPanel = new Panel();

rightToolbarPanel.setLayout(new GridLayout(1,2));

myPlayerPoint = new PlayerPoint(aTeam, aUsername, 0, 0);

//init display parameters.

this.setSize(250,370);

this.setEnabled(false);

this.setResizable(false);

mainPanel = new Panel();

mainPanel.setSize(250, 300);

nItems=2; zoom=false;

// Get the image from the path and sets the size

URL imageUrl = LocalizerGUI.class.getResource(“vubZoomIn.png”);

Image backgroundImage = Toolkit.getDefaultToolkit().getImage(imageUrl.getPath());

imageCanvas = new ImageCanvas(backgroundImage);

imageCanvas.setBounds(mainPanel.getBounds());

imageCanvas.addMouseListener(this);

imageCanvas.addMouseMotionListener(this);

imageCanvas.setVisible(true);

mainPanel.add(imageCanvas,BorderLayout.CENTER);

virtualItems = new List();

virtualItems.setBounds(mainPanel.getBounds());

virtualItems.setBackground(Color.WHITE);

virtualItems.setMultipleMode(false);

virtualItems.setVisible(false);

mainPanel.add(virtualItems);

mainPanel.setVisible(true);

this.add(mainPanel,BorderLayout.CENTER);

//in the center of the frame

// Create the information container with the toolbar panel (downContentPanel)

Container downContentPanel = new Container();

downContentPanel.setLayout(new BorderLayout());

this.add(downContentPanel, BorderLayout.SOUTH); //in the south of the frame

msgBar = new Label(“”, Label.CENTER);

downContentPanel.add(msgBar, BorderLayout.CENTER);

Panel toolbarPanel = new Panel();

toolbarPanel.setLayout(new GridLayout(1,2));

ActionListener buttonListener = new ActionListener() {

public void actionPerformed(ActionEvent ae){

String action = ae.getActionCommand();

if (action.equals(LocalizerGUI.SHOW_ITEMS)) {

items.setLabel(LocalizerGUI.DISPOSE_ITEMS);

imageCanvas.setVisible(false);

virtualItems.setVisible(true);

pack();

} else if (action.equals(LocalizerGUI.DISPOSE_ITEMS)) {

items.setLabel(LocalizerGUI.SHOW_ITEMS);

virtualItems.setVisible(false);

imageCanvas.setVisible(true);

pack();

} else if (action.equals(LocalizerGUI.ZOOM_IN)){

zoom=true;

imageCanvas.repaint();

zoomIn.setEnabled(false);

zoomOut.setEnabled(true);

} else if (action.equals(LocalizerGUI.ZOOM_OUT)) {

zoom=false;

imageCanvas.repaint();

zoomIn.setEnabled(true);

zoomOut.setEnabled(false);

} else if (action.equals(LocalizerGUI.EXIT)) {

setVisible(false);

dispose();

System.exit(0);

}

};

};

Panel zoomPanel = new Panel();

zoomPanel.setLayout(new GridLayout(1,2));

zoomOut = new Button(LocalizerGUI.ZOOM_OUT);

zoomOut.addActionListener(buttonListener);

zoomOut.setEnabled(false);

zoomPanel.add(zoomOut);

zoomIn = new Button(LocalizerGUI.ZOOM_IN);

zoomIn.addActionListener(buttonListener);

zoomIn.setEnabled(false);

zoomPanel.add(zoomIn);

Button exit = new Button(LocalizerGUI.EXIT);

exit.addActionListener(buttonListener);

/*Panel rightToolbarPanel = new Panel();

rightToolbarPanel.setLayout(new GridLayout(1,2));

setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

contentPanel_.setLayout(new BoxLayout(contentPanel_, BoxLayout.Y_AXIS));

Panel headers = new Panel();

GridBagLayout gridbag = new GridBagLayout();

GridBagConstraints c = new GridBagConstraints();

headers.setLayout(gridbag);

c.fill = GridBagConstraints.BOTH;

// FROM LABEL

c.weightx = 0;

Label fromLbl = new Label(“From: “);

gridbag.setConstraints(fromLbl, c);

headers.add(fromLbl);

// FROM TEXTFIELD

c.weightx = 1.0;

gridbag.setConstraints(from_, c);

headers.add(from_);

// new row

c.gridy = 1;

// TO LABEL

c.weightx = 0;

Label toLbl = new Label(“To: “);

gridbag.setConstraints(toLbl, c);

headers.add(toLbl);

// TO TEXTFIELD

c.weightx = 1.0;

c.gridwidth = GridBagConstraints.REMAINDER;

gridbag.setConstraints(to_, c);

headers.add(to_);

contentPanel_.add(headers);

contentPanel_.add(message_);

add(contentPanel_);

setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

contentPanel_.setLayout(new BoxLayout(contentPanel_, BoxLayout.Y_AXIS));

Panel headers = new Panel();

GridBagLayout gridbag = new GridBagLayout();

GridBagConstraints c = new GridBagConstraints();

headers.setLayout(gridbag);

c.fill = GridBagConstraints.BOTH;

// FROM LABEL

c.weightx = 0;

Label fromLbl = new Label(“From: “);

gridbag.setConstraints(fromLbl, c);

headers.add(fromLbl);

// FROM TEXTFIELD

c.weightx = 1.0;

gridbag.setConstraints(from_, c);

headers.add(from_);

// new row

c.gridy = 1;

// TO LABEL

c.weightx = 0;

Label toLbl = new Label(“To: “);

gridbag.setConstraints(toLbl, c);

headers.add(toLbl);

// TO TEXTFIELD

c.weightx = 1.0;

c.gridwidth = GridBagConstraints.REMAINDER;

gridbag.setConstraints(to_, c);

headers.add(to_);

contentPanel_.add(headers);

contentPanel_.add(message_);

add(contentPanel_);

setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

contentPanel_.setLayout(new BoxLayout(contentPanel_, BoxLayout.Y_AXIS));

Panel headers = new Panel();

GridBagLayout gridbag = new GridBagLayout();

GridBagConstraints c = new GridBagConstraints();

headers.setLayout(gridbag);

c.fill = GridBagConstraints.BOTH;

// FROM LABEL

c.weightx = 0;

Label fromLbl = new Label(“From: “);

gridbag.setConstraints(fromLbl, c);

headers.add(fromLbl);

// FROM TEXTFIELD

c.weightx = 1.0;

gridbag.setConstraints(from_, c);

headers.add(from_);

// new row

c.gridy = 1;

// TO LABEL

c.weightx = 0;

Label toLbl = new Label(“To: “);

gridbag.setConstraints(toLbl, c);

headers.add(toLbl);

// TO TEXTFIELD

c.weightx = 1.0;

c.gridwidth = GridBagConstraints.REMAINDER;

gridbag.setConstraints(to_, c);

headers.add(to_);

contentPanel_.add(headers);

contentPanel_.add(message_);

add(contentPanel_);

setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

contentPanel_.setLayout(new BoxLayout(contentPanel_, BoxLayout.Y_AXIS));

Panel headers = new Panel();

GridBagLayout gridbag = new GridBagLayout();

GridBagConstraints c = new GridBagConstraints();

headers.setLayout(gridbag);

c.fill = GridBagConstraints.BOTH;

// FROM LABEL

c.weightx = 0;

Label fromLbl = new Label(“From: “);

gridbag.setConstraints(fromLbl, c);

headers.add(fromLbl);

// FROM TEXTFIELD

c.weightx = 1.0;

gridbag.setConstraints(from_, c);

headers.add(from_);

// new row

c.gridy = 1;

// TO LABEL

c.weightx = 0;

Label toLbl = new Label(“To: “);

gridbag.setConstraints(toLbl, c);

headers.add(toLbl);

// TO TEXTFIELD

c.weightx = 1.0;

c.gridwidth = GridBagConstraints.REMAINDER;

gridbag.setConstraints(to_, c);

headers.add(to_);

contentPanel_.add(headers);

contentPanel_.add(message_);

add(contentPanel_);

Dimension d = Toolkit.getDefaultToolkit().getScreenSize();

setLayout(new BorderLayout());

Panel p = new Panel(new BorderLayout());

Panel pLabel;

Panel pText;

Panel pButton;

Panel pClearButton;

// (ulrivo): full size on screen with less than 640 width

if (d.width >= 640) {

pLabel

= new Panel(new GridLayout(8, 1, 10, 10));

pText

= new Panel(new GridLayout(8, 1, 10, 10));

pButton

= new Panel(new GridLayout(1, 2, 10, 10));

pClearButton = new Panel(new GridLayout(8, 1, 10, 10));

} else {

pLabel

= new Panel(new GridLayout(8, 1));

pText

= new Panel(new GridLayout(8, 1));

pButton

= new Panel(new GridLayout(1, 2));

pClearButton = new Panel(new GridLayout(8, 1));

}

p.add(“West”, pLabel);

p.add(“Center”, pText);

p.add(“South”, pButton);

p.add(“North”, createLabel(“”));

p.add(“East”, pClearButton);

p.setBackground(SystemColor.control);

pText.setBackground(SystemColor.control);

pLabel.setBackground(SystemColor.control);

pButton.setBackground(SystemColor.control);

pLabel.add(createLabel(“Recent:”));

removeIsNearbyProximityButton_.addActionListener(this);

isNearbyPanel_.add(removeIsNearbyProximityButton_);

this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

Panel flockNamePanel = new Panel(new FlowLayout(FlowLayout.LEFT));

Label flockNameLabel = new Label(“Name:”);

flockNamePanel.add(flockNameLabel);

flockNamePanel.add(flockNameField_);

add(flockNamePanel);

theProximitiesPanel_ = new Panel();

theProximitiesPanel_.setLayout(new BoxLayout(theProximitiesPanel_, BoxLayout.Y_AXIS));

add(theProximitiesPanel_);

saveButton_.setActionCommand(“Save”);

saveButton_.addActionListener(this);

removeIsNearbyProximityButton_.addActionListener(this);

isNearbyPanel_.add(removeIsNearbyProximityButton_);

this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

Panel flockNamePanel = new Panel(new FlowLayout(FlowLayout.LEFT));

Label flockNameLabel = new Label(“Name:”);

flockNamePanel.add(flockNameLabel);

flockNamePanel.add(flockNameField_);

add(flockNamePanel);

theProximitiesPanel_ = new Panel();

theProximitiesPanel_.setLayout(new BoxLayout(theProximitiesPanel_, BoxLayout.Y_AXIS));

add(theProximitiesPanel_);

saveButton_.setActionCommand(“Save”);

saveButton_.addActionListener(this);

removeIsNearbyProximityButton_.addActionListener(this);

isNearbyPanel_.add(removeIsNearbyProximityButton_);

this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

Panel flockNamePanel = new Panel(new FlowLayout(FlowLayout.LEFT));

Label flockNameLabel = new Label(“Name:”);

flockNamePanel.add(flockNameLabel);

flockNamePanel.add(flockNameField_);

add(flockNamePanel);

theProximitiesPanel_ = new Panel();

theProximitiesPanel_.setLayout(new BoxLayout(theProximitiesPanel_, BoxLayout.Y_AXIS));

add(theProximitiesPanel_);

saveButton_.setActionCommand(“Save”);

saveButton_.addActionListener(this);

removeIsNearbyProximityButton_.addActionListener(this);

isNearbyPanel_.add(removeIsNearbyProximityButton_);

this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

Panel flockNamePanel = new Panel(new FlowLayout(FlowLayout.LEFT));

Label flockNameLabel = new Label(“Name:”);

flockNamePanel.add(flockNameLabel);

flockNamePanel.add(flockNameField_);

add(flockNamePanel);

theProximitiesPanel_ = new Panel();

theProximitiesPanel_.setLayout(new BoxLayout(theProximitiesPanel_, BoxLayout.Y_AXIS));

add(theProximitiesPanel_);

saveButton_.setActionCommand(“Save”);

saveButton_.addActionListener(this);

removeIsNearbyProximityButton_.addActionListener(this);

isNearbyPanel_.add(removeIsNearbyProximityButton_);

this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

Panel flockNamePanel = new Panel(new FlowLayout(FlowLayout.LEFT));

Label flockNameLabel = new Label(“Name:”);

flockNamePanel.add(flockNameLabel);

flockNamePanel.add(flockNameField_);

add(flockNamePanel);

theProximitiesPanel_ = new Panel();

theProximitiesPanel_.setLayout(new BoxLayout(theProximitiesPanel_, BoxLayout.Y_AXIS));

add(theProximitiesPanel_);

saveButton_.setActionCommand(“Save”);

saveButton_.addActionListener(this);

Related Class of java.awt.Panel

Copyright © 2011 www.androidadb.com. All rights reserved. All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc. Contact . See also:

|

|

|

Read More Post