List of usage examples for java.awt Container add
public Component add(Component comp)
From source file:ClipArea.java
public ClipArea() { super();/*from w ww . j av a 2 s .c o m*/ Container contentPane = getContentPane(); canvas = new MyCanvas(); contentPane.add(canvas); JPanel panel = new JPanel(); panel.setLayout(new GridLayout(1, 2)); clipButton = new JRadioButton("Clip", true); clipButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { canvas.clip = true; canvas.clipFurther = false; canvas.repaint(); } }); clipFurButton = new JRadioButton("Clip Further"); clipFurButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { canvas.clipFurther = true; canvas.repaint(); } }); ButtonGroup group = new ButtonGroup(); group.add(clipButton); group.add(clipFurButton); panel.add(clipButton); panel.add(clipFurButton); contentPane.add(BorderLayout.SOUTH, panel); // 4. Add a window listener to close the frame properly. addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); pack(); setVisible(true); }
From source file:ExecDemoNS.java
/** Constructor - set up strings and things. */ public ExecDemoNS(String prog) { super("ExecDemo: " + prog); String osname = System.getProperty("os.name"); if (osname == null) throw new IllegalArgumentException("no os.name"); if (prog.equals("netscape")) program = // Windows or UNIX only for now, sorry Mac fans (osname.toLowerCase().indexOf("windows") != -1) ? "c:/program files/netscape/communicator/program/netscape.exe" : "/usr/local/netscape/netscape"; else// w w w .j ava2s . c o m program = prog; Container cp = getContentPane(); cp.setLayout(new FlowLayout()); JButton b; cp.add(b = new JButton("Exec")); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { runProg(); } }); cp.add(b = new JButton("Wait")); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { doWait(); } }); cp.add(b = new JButton("Exit")); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { System.exit(0); } }); pack(); }
From source file:ColorComposite.java
public ColorComposite() { super();/*from w w w.ja va 2s . c o m*/ Container container = getContentPane(); canvas = new MyCanvas(); container.add(canvas); JPanel panel = new JPanel(); JLabel label = new JLabel("Color-Composite: "); JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 100, 65); slider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { JSlider tempSlider = (JSlider) e.getSource(); alphaValue = (float) (tempSlider.getValue() / 100.0); textField.setText(Float.toString(alphaValue)); canvas.repaint(); } }); textField = new JTextField("0.65", 4); panel.add(label); panel.add(slider); panel.add(textField); container.add(BorderLayout.SOUTH, panel); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); setSize(450, 450); setVisible(true); }
From source file:RasterDemo.java
public RasterDemo() { super();//from w ww. j a v a 2 s. co m Container container = getContentPane(); displayPanel = new RasterPanel(); container.add(displayPanel); Box box = Box.createHorizontalBox(); flipButton = new JToggleButton("Flip the Image"); flipButton.addActionListener(new ButtonListener()); box.add(Box.createHorizontalGlue()); box.add(flipButton); box.add(Box.createHorizontalGlue()); container.add(box, BorderLayout.SOUTH); addWindowListener(new WindowEventHandler()); setSize(450, 400); show(); }
From source file:GridTest.java
public GridTest(int rows, int cols) { Container pane = getContentPane(); pane.setLayout(new GridLayout(rows, cols)); for (int i = 0; i < 20; i++) { JButton button = new JButton(Integer.toString(i + 1)); pane.add(button); }//from w ww. j ava 2 s. co m }
From source file:AlphaCompositeDemo.java
public AlphaCompositeDemo() { super();/*w w w . j a v a 2 s. c o m*/ Container container = getContentPane(); canvas = new MyCanvas(); container.add(canvas); rulesBox = new JComboBox(rulesLabels); rulesBox.setSelectedIndex(0); rulesBox.setAlignmentX(Component.LEFT_ALIGNMENT); rulesBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JComboBox cb = (JComboBox) e.getSource(); canvas.compositeRule = rules[cb.getSelectedIndex()]; canvas.repaint(); } }); slider.setPaintTicks(true); slider.setMajorTickSpacing(25); slider.setMinorTickSpacing(25); slider.setPaintLabels(true); slider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { JSlider slider = (JSlider) e.getSource(); canvas.alphaValue = (float) slider.getValue() / 100; canvas.repaint(); } }); JPanel panel = new JPanel(); panel.setLayout(new GridLayout(1, 3)); panel.add(rulesBox); panel.add(new JLabel("Alpha Adjustment x E-2: ", JLabel.RIGHT)); panel.add(slider); container.add(panel, BorderLayout.SOUTH); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); setSize(500, 300); setVisible(true); }
From source file:ColorConvertDemo.java
public ColorConvertDemo() { super();//from ww w . j av a2 s . c o m Container container = getContentPane(); displayPanel = new ColorPanel(); container.add(displayPanel); JPanel panel = new JPanel(); panel.setLayout(new GridLayout(1, 2)); panel.setBorder(new TitledBorder("Click the Gray Scale Button to Create Gray Scale Image...")); grayButton = new JButton("Gray Scale"); grayButton.addActionListener(new ButtonListener()); resetButton = new JButton("Reset"); resetButton.addActionListener(new ButtonListener()); panel.add(grayButton); panel.add(resetButton); container.add(BorderLayout.SOUTH, panel); addWindowListener(new WindowEventHandler()); setSize(displayPanel.getWidth(), displayPanel.getHeight() + 15); setVisible(true); }
From source file:ManyGeneralPath.java
public void init() { Container container = getContentPane(); JPanel panel = new JPanel(); canvas = new DrawingCanvas(); container.add(canvas); }