import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.applet.*;
public class LayoutExampleApplet extends JApplet {
private JTabbedPane tabbedPane;
private JPanel borderPanel;
private JPanel flowPanel;
private JPanel gridPanel;
public void buildGui() {
tabbedPane = new JTabbedPane(JTabbedPane.TOP);
borderPanel = new JPanel();
gridPanel = new JPanel();
flowPanel = new JPanel();
this.add(tabbedPane);
tabbedPane.addTab("FlowLayout", flowPanel);
tabbedPane.addTab("GridLayout", gridPanel);
tabbedPane.addTab("BorderLayout", borderPanel);
borderPanel.setLayout(new BorderLayout());
gridPanel.setLayout(new GridLayout(2,3)); // 2 rows, 3 cols
flowPanel.setLayout(new FlowLayout( FlowLayout.RIGHT ));
// labels to identify panels
JLabel northLabel = new JLabel( "NORTH" );
JLabel eastLabel = new JLabel( "EAST" );
JLabel westLabel = new JLabel( "WEST" );
JLabel centerLabel = new JLabel( "CENTER" );
JLabel southLabel = new JLabel( "SOUTH" );
centerLabel.setAlignmentY( JLabel.CENTER_ALIGNMENT );
// adding componenets to show the layouts
JPanel centerPanel = new JPanel() ;
JPanel southPanel = new JPanel();
JPanel northPanel = new JPanel() ;
JPanel eastPanel = new JPanel();
JPanel westPanel = new JPanel();
northPanel.add(northLabel);
southPanel.add(southLabel);
centerPanel.add(centerLabel);
westPanel.add(westLabel);
eastPanel.add(eastLabel);
// repaint panels backgrounds
centerPanel.setBackground( Color.RED );
southPanel.setBackground( Color.GREEN );
northPanel.setBackground( Color.ORANGE );
eastPanel.setBackground( Color.YELLOW );
westPanel.setBackground( Color.CYAN );
borderPanel.add(northPanel, BorderLayout.NORTH);
borderPanel.add(southPanel, BorderLayout.SOUTH);
borderPanel.add(eastPanel, BorderLayout.EAST);
borderPanel.add(westPanel, BorderLayout.WEST);
borderPanel.add(centerPanel, BorderLayout.CENTER);
gridPanel.add(new JLabel("1", JLabel.CENTER));
gridPanel.add(new JLabel("2", JLabel.CENTER));
gridPanel.add(new JLabel("3", JLabel.CENTER));
gridPanel.add(new JLabel("4", JLabel.CENTER));
gridPanel.add(new JLabel("5", JLabel.CENTER));
gridPanel.add(new JLabel("6", JLabel.CENTER));
flowPanel.add(new JLabel("Label1"));
flowPanel.add(new JLabel("Label2"));
flowPanel.add(new JLabel("Label3"));
flowPanel.add(new JLabel("Label4"));
flowPanel.add(new JLabel("Label5"));
flowPanel.add(new JLabel("Label6"));
}
public void init( ) {
buildGui();
repaint();
}
}
http://users.atw.hu/ngweb/applets/layoutapplet.html
Nincsenek megjegyzések:
Megjegyzés küldése