Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package swingapplication;
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- public class RozkladyAkcja implements ActionListener {
- /** Creates a new instance of RozkladyAkcja */
- RozkladyAkcja() {
- String []layoutNamesTab = { "Flow Layout", "Grid Layout", "Border Layout"};
- LayoutManager []rozkladyTab = { new FlowLayout(30), new GridLayout(3,4), new BorderLayout() };
- JFrame okno = new JFrame("Okno w Swing");
- okno.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
- Container kontener = okno.getContentPane();
- kontener.setLayout(new GridLayout(2,5));
- for (int i=0; i<layoutNamesTab.length-1; i++) {
- Panel p = new Panel();
- p.setLayout(rozkladyTab[i]);
- for (int j=0; j<5; j++) {
- JButton jb = new JButton("przycisk "+(j+1));
- jb.addActionListener(new SetFont());
- p.add(jb);
- }
- kontener.add(p);
- }
- //Border layout
- String []kierunki = { "West", "North", "East", "South", "Center"};
- JPanel p = new JPanel();
- p.setLayout(rozkladyTab[rozkladyTab.length-1]);
- for (int j=0; j<5; j++) {
- JButton jb = new JButton("przycisk "+(j+1));
- jb.addActionListener(this);
- jb.setToolTipText("AAAAAAAAAAAA");
- p.add(jb,kierunki[j]);
- }
- kontener.add(p);
- JPanel jp = new JPanel(new FlowLayout(FlowLayout.TRAILING,30,0));
- JButton jbutton = new JButton("Przycisk na JPanel'u");
- jbutton.addActionListener(this);
- jp.add(jbutton);
- kontener.add(jp);
- okno.pack();
- okno.setVisible(true);
- }
- public void actionPerformed(ActionEvent ae) {
- JComponent jc = (JComponent)ae.getSource();
- jc.setToolTipText(ae.getActionCommand());
- if (ae.getActionCommand().equals("Przycisk na JPanel'u"))
- JOptionPane.showMessageDialog(jc.getParent(),jc.getToolTipText(),
- "Podpowiedz na przycisku!",JOptionPane.INFORMATION_MESSAGE);
- }
- }
- class SetFont implements ActionListener {
- public void actionPerformed(ActionEvent ae) {
- JComponent jc = (JComponent)ae.getSource();
- jc.setFont(new Font("DialogInput", Font.BOLD, 16));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement