Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- public class Gui extends JFrame{
- // Variables
- private JButton lb;
- private JButton cb;
- private JButton rb;
- private FlowLayout layout;
- private Container container;
- // Constructor
- public Gui(){
- // Basics
- super("JFrame's title");
- layout = new FlowLayout();
- setLayout(layout);
- container = getContentPane();
- // Buttons
- lb = new JButton("Left");
- add(lb);
- lb.addActionListener(
- new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent event) {
- layout.setAlignment(FlowLayout.LEFT);
- layout.layoutContainer(container);
- }
- }
- );
- cb = new JButton("Center");
- add(cb);
- cb.addActionListener(
- new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent event) {
- layout.setAlignment(FlowLayout.CENTER);
- layout.layoutContainer(container);
- }
- }
- );
- rb = new JButton("Right");
- add(rb);
- rb.addActionListener(
- new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent event) {
- layout.setAlignment(FlowLayout.RIGHT);
- layout.layoutContainer(container);
- }
- }
- );
- }
- // Main Function
- public static void main(String[] agrs){
- Gui gui = new Gui();
- gui.setDefaultCloseOperation(EXIT_ON_CLOSE);
- gui.setSize(400, 400);
- gui.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement