-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJDemoFlowLayout.java
More file actions
36 lines (34 loc) · 967 Bytes
/
Copy pathJDemoFlowLayout.java
File metadata and controls
36 lines (34 loc) · 967 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class JDemoFlowLayout extends JFrame implements ActionListener
{
private JButton lb = new JButton("L Button");
private JButton rb = new JButton("R Button");
private Container con = getContentPane();
private FlowLayout layout = new FlowLayout();
public JDemoFlowLayout()
{
con.setLayout(layout);
con.add(lb);
con.add(rb);
lb.addActionListener(this);
rb.addActionListener(this);
setSize(500, 100);
}
public void actionPerformed(ActionEvent event)
{
Object source = event.getSource();
if( source == lb)
layout.setAlignment(FlowLayout.LEFT);
else
layout.setAlignment(FlowLayout.RIGHT);
con.invalidate();
con.validate();
}
public static void main(String[] args)
{
JDemoFlowLayout frame = new JDemoFlowLayout();
frame.setVisible(true);
}
}