use of java.awt.Panel in project GCViewer by chewiebug.
the class ScreenCenteredDialog method initComponents.
protected void initComponents() {
Panel buttonPanel = new Panel();
buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
JButton okButton = new JButton(LocalisationHelper.getString("button_ok"));
okButton.setActionCommand(ACTION_OK);
okButton.addActionListener(this);
buttonPanel.add(okButton);
getContentPane().add("South", buttonPanel);
}
use of java.awt.Panel in project yyl_example by Relucent.
the class IGOMatrix method createControl.
protected void createControl() {
frame.getContentPane().setLayout(new GridBagLayout());
GridBagConstraints gridData = new GridBagConstraints();
canvasBoard = new IGOBoard(19);
gridData.fill = GridBagConstraints.BOTH;
gridData.weightx = 5;
gridData.weighty = 1;
frame.getContentPane().add(canvasBoard, gridData);
gridData = new GridBagConstraints();
panel = new Panel();
gridData.weightx = 1;
gridData.weighty = 1;
frame.getContentPane().add(panel, gridData);
button = new JButton();
panel.add(button, gridData);
final JPanel panel_1 = new JPanel();
panel.add(panel_1, new GridBagConstraints());
}
use of java.awt.Panel in project triplea by triplea-game.
the class TileImageBreaker method loadImage.
/**
* Asks the user to select an image and then it loads it up into an Image
* object and returns it to the calling class.
*
* @return The loaded image.
*/
private Image loadImage() {
ToolLogger.info("Select the map");
final String mapName = new FileOpen("Select The Map", mapFolderLocation, ".gif", ".png").getPathString();
if (mapName != null) {
final Image img = Toolkit.getDefaultToolkit().createImage(mapName);
final MediaTracker tracker = new MediaTracker(new Panel());
tracker.addImage(img, 1);
try {
tracker.waitForAll();
return img;
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
}
}
return null;
}
use of java.awt.Panel in project JSettlers2 by jdmonin.
the class NewGameOptionsFrame method initInterface_Opt1.
/**
* Add one GridBagLayout row with this game option (component and label(s)).
* The option's descriptive text may have "#" as a placeholder for where
* int/enum value is specified (IntTextField or Choice-dropdown).
* @param op Option data
* @param oc Component with option choices (popup menu, textfield, etc).
* If oc is a {@link TextField} or {@link Choice}, and hasCB,
* changing the component's value will set the checkbox.
* <tt>oc</tt> will be added to {@link #optsControls} and {@link #controlsOpts}.
* @param hasCB Add a checkbox? If oc is {@link Checkbox}, set this true;
* it won't add a second checkbox.
* The checkbox will be added to {@link #boolOptCheckboxes} and {@link #controlsOpts}.
* @param allowPH Allow the "#" placeholder within option desc?
* @param bp Add to this panel
* @param gbl Use this layout
* @param gbc Use these constraints; gridwidth will be set to 1 and then REMAINDER
*/
private void initInterface_Opt1(SOCGameOption op, Component oc, boolean hasCB, boolean allowPH, JPanel bp, GridBagLayout gbl, GridBagConstraints gbc) {
Label L;
// reminder: same gbc widths/weights are used in initInterface_UserPrefs/initInterface_Pref1
gbc.gridwidth = 1;
gbc.weightx = 0;
if (hasCB) {
Checkbox cb;
if (oc instanceof Checkbox)
cb = (Checkbox) oc;
else
cb = new Checkbox();
controlsOpts.put(cb, op);
cb.setState(op.getBoolValue());
cb.setEnabled(!readOnly);
gbl.setConstraints(cb, gbc);
bp.add(cb);
if (!readOnly) {
boolOptCheckboxes.put(op.key, cb);
// for op's ChangeListener and userChanged
cb.addItemListener(this);
}
} else {
// to fill checkbox's column
L = new Label();
gbl.setConstraints(L, gbc);
bp.add(L);
}
final String opDesc = op.getDesc();
final int placeholderIdx = allowPH ? opDesc.indexOf('#') : -1;
// with FlowLayout
Panel optp = new Panel();
try {
FlowLayout fl = (FlowLayout) (optp.getLayout());
fl.setAlignment(FlowLayout.LEFT);
fl.setVgap(0);
fl.setHgap(0);
} catch (Throwable fle) {
}
// Any text to the left of placeholder in op.desc?
if (placeholderIdx > 0) {
L = new Label(opDesc.substring(0, placeholderIdx));
L.setForeground(LABEL_TXT_COLOR);
optp.add(L);
if (hasCB && !readOnly) {
controlsOpts.put(L, op);
// Click label to toggle checkbox
L.addMouseListener(this);
}
}
// TextField or Choice or JComboBox at placeholder position
if (!(oc instanceof Checkbox)) {
controlsOpts.put(oc, op);
oc.setEnabled(!readOnly);
optp.add(oc);
if (hasCB && !readOnly) {
if (oc instanceof TextField) {
// for enable/disable
((TextField) oc).addTextListener(this);
// for ESC/ENTER
((TextField) oc).addKeyListener(this);
} else if (oc instanceof Choice) {
// for related cb, and op.ChangeListener and userChanged
((Choice) oc).addItemListener(this);
} else if (oc instanceof JComboBox) {
// for related cb, and op.ChangeListener and userChanged
((JComboBox) oc).addActionListener(this);
}
}
}
if (!readOnly)
optsControls.put(op.key, oc);
// the text label if there is no placeholder (placeholderIdx == -1).
if (placeholderIdx + 1 < opDesc.length()) {
L = new Label(opDesc.substring(placeholderIdx + 1));
L.setForeground(LABEL_TXT_COLOR);
optp.add(L);
if (hasCB && !readOnly) {
controlsOpts.put(L, op);
// Click label to toggle checkbox
L.addMouseListener(this);
}
}
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbc.weightx = 1;
gbl.setConstraints(optp, gbc);
bp.add(optp);
}
use of java.awt.Panel in project JSettlers2 by jdmonin.
the class SOCConnectOrPracticePanel method initInterfaceElements.
/**
* Interface setup for constructor.
* Most elements are part of a sub-panel occupying most of this Panel, and using FlowLayout.
* The exception is a Label at bottom with the version and build number.
*/
private void initInterfaceElements() {
GridBagLayout gbl = new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();
// Actual button panel
Panel bp = new Panel(gbl);
gbc.fill = GridBagConstraints.BOTH;
gbc.gridwidth = GridBagConstraints.REMAINDER;
// "Welcome to JSettlers! Please choose an option."
topText = new Label(strings.get("pcli.cpp.welcomeheading"));
topText.setAlignment(Label.CENTER);
gbl.setConstraints(topText, gbc);
bp.add(topText);
/**
* Interface setup: Connect to a Server
*/
// "Connect to a Server"
connserv = new Button(strings.get("pcli.cpp.connecttoaserv"));
gbl.setConstraints(connserv, gbc);
bp.add(connserv);
connserv.addActionListener(this);
/**
* Interface setup: Practice
*/
// "Practice" - same as SOCPlayerClient button
prac = new Button(strings.get("pcli.main.practice"));
gbl.setConstraints(prac, gbc);
bp.add(prac);
prac.addActionListener(this);
/**
* Interface setup: Start a Server
*/
// "Start a Server"
runserv = new Button(strings.get("pcli.cpp.startserv"));
gbl.setConstraints(runserv, gbc);
if (!canLaunchServer)
runserv.setEnabled(false);
bp.add(runserv);
/**
* Interface setup: sub-panels (not initially visible)
*/
// panel_conn setup
panel_conn = initInterface_conn();
panel_conn.setVisible(false);
gbl.setConstraints(panel_conn, gbc);
bp.add(panel_conn);
if (canLaunchServer) {
runserv.addActionListener(this);
// panel_run setup
panel_run = initInterface_run();
panel_run.setVisible(false);
gbl.setConstraints(panel_run, gbc);
bp.add(panel_run);
} else {
panel_run = null;
}
// Final assembly setup
add(bp, BorderLayout.CENTER);
Label verl = new Label(strings.get("pcli.cpp.jsettlers.versionbuild", Version.version(), Version.buildnum()));
// "JSettlers " + Version.version() + " build " + Version.buildnum()
verl.setAlignment(Label.CENTER);
// off-white
verl.setForeground(new Color(252, 251, 243));
add(verl, BorderLayout.SOUTH);
}
Aggregations