package com.drbob42.jbjar.tip23; import java.awt.*; import borland.jbcl.view.*; import borland.jbcl.control.*; import java.awt.event.*; public class SpacerFrame extends Frame { BorderLayout borderLayout1 = new BorderLayout(); Panel panel1 = new Panel(); BorderLayout borderLayout2 = new BorderLayout(); Panel settingsPanel = new Panel(); Panel panel3 = new Panel(); GridLayout gridLayout1 = new GridLayout(); Panel panel2 = new Panel(); Panel panel4 = new Panel(); Panel panel5 = new Panel(); FlowLayout flowLayout1 = new FlowLayout(); Label label1 = new Label(); Label label2 = new Label(); TextField widthTextField = new TextField(); Label label3 = new Label(); TextField heightTextField = new TextField(); FlowLayout flowLayout2 = new FlowLayout(); FlowLayout flowLayout3 = new FlowLayout(); Button previewButton = new Button(); Spacer spacer1 = new Spacer(); Panel panel7 = new Panel(); FlowLayout flowLayout5 = new FlowLayout(); Label label5 = new Label(); Spacer spacer2 = new Spacer(); Label label6 = new Label(); FlowLayout flowLayout4 = new FlowLayout(); public SpacerFrame() { try { jbInit(); } catch (Exception e) { e.printStackTrace(); } } private void jbInit() throws Exception { this.setLayout(borderLayout1); this.setSize(new Dimension(476, 204)); this.setTitle("Play with Spacer component"); this.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(WindowEvent e) { this_windowClosing(e); } }); panel3.setLayout(flowLayout4); gridLayout1.setRows(3); gridLayout1.setColumns(1); panel4.setLayout(flowLayout3); panel5.setLayout(flowLayout2); flowLayout1.setAlignment(0); label1.setText("Change width and height of spacer and press the Preview button to " + "see the result."); label2.setText("Width:"); widthTextField.setText("10"); label3.setText("Height:"); heightTextField.setText("10"); flowLayout3.setAlignment(0); previewButton.setLabel("Preview"); panel7.setBackground(SystemColor.textHighlight); previewButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { previewButton_actionPerformed(e); } }); flowLayout5.setHgap(0); flowLayout5.setVgap(0); label5.setForeground(SystemColor.textHighlightText); label5.setText("Label followed by spacer"); label6.setForeground(SystemColor.textHighlightText); label6.setText("Label after spacer"); flowLayout4.setVgap(0); flowLayout4.setHgap(0); panel7.setLayout(flowLayout5); flowLayout2.setAlignment(0); panel2.setLayout(flowLayout1); settingsPanel.setLayout(gridLayout1); panel1.setLayout(borderLayout2); this.add(panel1, BorderLayout.CENTER); panel1.add(settingsPanel, BorderLayout.NORTH); settingsPanel.add(panel2, null); panel2.add(label1, null); settingsPanel.add(panel5, null); panel5.add(label2, null); panel5.add(widthTextField, null); panel5.add(spacer1, null); panel5.add(label3, null); panel5.add(heightTextField, null); settingsPanel.add(panel4, null); panel4.add(previewButton, null); panel1.add(panel3, BorderLayout.CENTER); panel3.add(panel7, null); panel7.add(label6, null); panel7.add(spacer2, null); panel7.add(label5, null); } void this_windowClosing(WindowEvent e) { setVisible(false); } void previewButton_actionPerformed(ActionEvent e) { int w = Integer.parseInt(widthTextField.getText()); int h = Integer.parseInt(heightTextField.getText()); Dimension d = new Dimension(w, h); spacer2.setPreferredSize(d); spacer2.setMinimumSize(d); spacer2.invalidate(); this.validate(); } }