Skip to content

Instantly share code, notes, and snippets.

@irinaaZ
Created June 21, 2018 19:54
Show Gist options
  • Save irinaaZ/6c3d6665297609c9876af5138ab12029 to your computer and use it in GitHub Desktop.
Save irinaaZ/6c3d6665297609c9876af5138ab12029 to your computer and use it in GitHub Desktop.
package JUnittasks;
import javax.swing.*;
import java.awt.*;
public class Align extends JFrame {
private final JCheckBox snapToGrid, showGrid;
private final JLabel labelX, labelY;
private final JTextField fieldX, fieldY;
private final JButton ok, cancel, help;
public Align(){
super("Align");
Container container = getContentPane();
snapToGrid = new JCheckBox("Snap To Grid");
showGrid = new JCheckBox("Show Grid");
labelX = new JLabel("X:");
labelY = new JLabel("Y:");
fieldX = new JTextField("8", 3);
fieldY = new JTextField("8", 3);
ok = new JButton("Ok");
cancel = new JButton("Cancel");
help = new JButton("Help");
//snap to grid and showgrid elements
Box box1 = Box.createVerticalBox();
//x:, y:
Box box2 = Box.createVerticalBox();
JPanel panelX = new JPanel();
JPanel panelY = new JPanel();
//ok, help, cancel buttons
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new GridLayout(3, 1,5,5));
//x and y labels + textfields
panelX.setLayout(new FlowLayout());
panelY.setLayout(new FlowLayout());
panelX.add(labelX);
panelX.add(fieldX);
panelY.add(labelY);
panelY.add(fieldY);
//add tp grid snap to grid and showgrid elements
box1.add(snapToGrid);
box1.add(showGrid);
//add x: and y:
box2.add(panelX);
box2.add(panelY);
//add buttons
buttonPanel.add(ok);
buttonPanel.add(cancel);
buttonPanel.add(help);
//add all elements to the container
container.setLayout(new FlowLayout());
container.add(box1);
container.add(box2);
container.add(buttonPanel);
setSize(300, 150);
setVisible(true);
setLocationRelativeTo(null);
}
public static void main(String[] args) {
Align align = new Align();
align.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment