Restore
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel{
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
g.drawRect(30,10,60,60);
|
||||
g.drawRect(10,20,60,60);
|
||||
g.drawLine(30, 10, 10, 20);
|
||||
g.drawLine(90, 70, 70, 80);
|
||||
g.drawLine(90, 10, 70, 20);
|
||||
g.drawLine(30, 70, 10, 80);
|
||||
|
||||
g.setColor(Color.BLUE);
|
||||
g.drawOval(120, 10, 60, 15);
|
||||
g.drawOval(120, 70, 60, 15);
|
||||
g.drawLine(120, 17, 120, 80);
|
||||
g.drawLine(180, 27, 180, 80);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel{
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.BLUE);
|
||||
g.drawString("hello",20, 80);
|
||||
g.drawString("hello",
|
||||
(int)Math.round(Math.random() * this.getWidth()),
|
||||
(int)Math.round(Math.random() * this.getHeight()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title"); //if comment out, the title would be blank
|
||||
this.setSize(400, 300); //if comment out, the initiated size would be 0
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //if comment out, the program would still running after clicked close button
|
||||
this.setLocationRelativeTo(null); //if comment out, the frame would appear at (0, 0)
|
||||
|
||||
JPanel p1 = new JPanel();
|
||||
BorderLayout bl = new BorderLayout();
|
||||
p1.setLayout(bl);
|
||||
p1.add(new JButton("b1"), BorderLayout.LINE_START);
|
||||
p1.add(new JButton("b2"), BorderLayout.LINE_END);
|
||||
|
||||
JPanel p2 = new JPanel();
|
||||
FlowLayout f1 = new FlowLayout(FlowLayout.CENTER);
|
||||
p2.setLayout(f1);
|
||||
JLabel l = new JLabel("Enter your name: ");
|
||||
p2.add(l);
|
||||
JTextField tx = new JTextField("Type Text Here");
|
||||
p2.add(tx);
|
||||
|
||||
JPanel p3 = new JPanel();
|
||||
GridLayout g1 = new GridLayout(2, 2);
|
||||
p3.setLayout(g1);
|
||||
JCheckBox cb = new JCheckBox("I agree");
|
||||
p3.add(cb);
|
||||
JRadioButton rb = new JRadioButton("Yes");
|
||||
p3.add(rb);
|
||||
JComboBox<String> cb1 = new JComboBox<String>(new String[]{"Red", "Green", "Blue"});
|
||||
p3.add(cb1);
|
||||
JComboBox<Integer> cb2 = new JComboBox<Integer>(new Integer[]{2, 7, -3, 24});
|
||||
p3.add(cb2);
|
||||
|
||||
this.setVisible(true); //if comment out, the window would not be visible
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel{
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
g.drawRect(20,20,60,60);
|
||||
g.drawRect(10,10,60,60);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel{
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
g.drawRect(30,10,60,60);
|
||||
g.drawRect(10,20,60,60);
|
||||
g.drawLine(30, 10, 10, 20);
|
||||
g.drawLine(90, 70, 70, 80);
|
||||
g.drawLine(90, 10, 70, 10);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel{
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
g.drawRect(30,10,60,60);
|
||||
g.drawRect(10,20,60,60);
|
||||
g.drawLine(30, 10, 10, 20);
|
||||
g.drawLine(90, 70, 70, 80);
|
||||
g.drawLine(90, 10, 70, 20);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title"); //if comment out, the title would be blank
|
||||
this.setSize(400, 300); //if comment out, the initiated size would be 0
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //if comment out, the program would still running after clicked close button
|
||||
this.setLocationRelativeTo(null); //if comment out, the frame would appear at (0, 0)
|
||||
|
||||
JButton b1 = new JButton("b1");
|
||||
this.add(new JButton("b1"), BorderLayout.LINE_START);
|
||||
JButton b2 = new JButton("b2");
|
||||
this.add(new JButton("b2"), BorderLayout.LINE_END);
|
||||
|
||||
/* Only one button appear as Java would detect same button and remove
|
||||
JButton b = new JButton("B1");
|
||||
this.add(b);
|
||||
this.add(b);
|
||||
*/
|
||||
|
||||
/*
|
||||
FlowLayout f1 = new FlowLayout(FlowLayout.LEFT, 20, 40);
|
||||
this.setLayout(f1);
|
||||
*/
|
||||
|
||||
/*
|
||||
GridLayout g1 = new GridLayout(5, 5);
|
||||
this.setLayout(g1);
|
||||
*/
|
||||
//the program presents in 4*2 layout
|
||||
//the program did not use the specified rows and columns, because the lack numbers of components
|
||||
|
||||
BorderLayout bl = new BorderLayout();
|
||||
this.setLayout(bl);
|
||||
|
||||
JLabel l = new JLabel("Enter your name: ");
|
||||
this.add(l, BorderLayout.LINE_START);
|
||||
JTextField tx = new JTextField("Type Text Here");
|
||||
this.add(tx, BorderLayout.CENTER);
|
||||
JCheckBox cb = new JCheckBox("I agree");
|
||||
this.add(cb, BorderLayout.LINE_END);
|
||||
JRadioButton rb = new JRadioButton("Yes");
|
||||
this.add(rb, BorderLayout.AFTER_LINE_ENDS);
|
||||
JComboBox<String> cb1 = new JComboBox<String>(new String[]{"Red", "Green", "Blue"});
|
||||
this.add(cb1, BorderLayout.CENTER);
|
||||
JComboBox<Integer> cb2 = new JComboBox<Integer>(new Integer[]{2, 7, -3, 24});
|
||||
this.add(cb2, BorderLayout.LINE_END);
|
||||
|
||||
//when stretching the window, the components would realign to one row if space permits
|
||||
|
||||
this.setVisible(true); //if comment out, the window would not be visible
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title"); //if comment out, the title would be blank
|
||||
this.setSize(400, 300); //if comment out, the initiated size would be 0
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //if comment out, the program would still running after clicked close button
|
||||
this.setLocationRelativeTo(null); //if comment out, the frame would appear at (0, 0)
|
||||
|
||||
JPanel p1 = new JPanel();
|
||||
BorderLayout bl = new BorderLayout();
|
||||
p1.setLayout(bl);
|
||||
this.add(p1);
|
||||
p1.add(new JButton("b1"), BorderLayout.LINE_START);
|
||||
p1.add(new JButton("b2"), BorderLayout.LINE_END);
|
||||
|
||||
JPanel p2 = new JPanel();
|
||||
FlowLayout f1 = new FlowLayout(FlowLayout.CENTER);
|
||||
p2.setLayout(f1);
|
||||
this.add(p2);
|
||||
JLabel l = new JLabel("Enter your name: ");
|
||||
p2.add(l);
|
||||
JTextField tx = new JTextField("Type Text Here");
|
||||
p2.add(tx);
|
||||
|
||||
JPanel p3 = new JPanel();
|
||||
GridLayout g1 = new GridLayout(2, 2);
|
||||
p3.setLayout(g1);
|
||||
//this.add(p3);
|
||||
JCheckBox cb = new JCheckBox("I agree");
|
||||
p3.add(cb);
|
||||
JRadioButton rb = new JRadioButton("Yes");
|
||||
p3.add(rb);
|
||||
JComboBox<String> cb1 = new JComboBox<String>(new String[]{"Red", "Green", "Blue"});
|
||||
p3.add(cb1);
|
||||
JComboBox<Integer> cb2 = new JComboBox<Integer>(new Integer[]{2, 7, -3, 24});
|
||||
p3.add(cb2);
|
||||
|
||||
this.setVisible(true); //if comment out, the window would not be visible
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title"); //if comment out, the title would be blank
|
||||
this.setSize(400, 300); //if comment out, the initiated size would be 0
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //if comment out, the program would still running after clicked close button
|
||||
this.setLocationRelativeTo(null); //if comment out, the frame would appear at (0, 0)
|
||||
|
||||
JPanel p1 = new JPanel();
|
||||
BorderLayout bl = new BorderLayout();
|
||||
p1.setLayout(bl);
|
||||
this.add(p1);
|
||||
p1.add(new JButton("b1"), BorderLayout.LINE_START);
|
||||
p1.add(new JButton("b2"), BorderLayout.LINE_END);
|
||||
|
||||
JPanel p2 = new JPanel();
|
||||
FlowLayout f1 = new FlowLayout(FlowLayout.CENTER);
|
||||
p2.setLayout(f1);
|
||||
this.add(p2);
|
||||
JLabel l = new JLabel("Enter your name: ");
|
||||
p2.add(l);
|
||||
JTextField tx = new JTextField("Type Text Here");
|
||||
p2.add(tx);
|
||||
|
||||
JPanel p3 = new JPanel();
|
||||
GridLayout g1 = new GridLayout(2, 2);
|
||||
p3.setLayout(g1);
|
||||
this.add(p3);
|
||||
JCheckBox cb = new JCheckBox("I agree");
|
||||
p3.add(cb);
|
||||
JRadioButton rb = new JRadioButton("Yes");
|
||||
p3.add(rb);
|
||||
JComboBox<String> cb1 = new JComboBox<String>(new String[]{"Red", "Green", "Blue"});
|
||||
p3.add(cb1);
|
||||
JComboBox<Integer> cb2 = new JComboBox<Integer>(new Integer[]{2, 7, -3, 24});
|
||||
p3.add(cb2);
|
||||
|
||||
this.setVisible(true); //if comment out, the window would not be visible
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel{
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
g.drawRect(30,10,60,60);
|
||||
g.drawRect(10,20,60,60);
|
||||
g.drawLine(30, 10, 10, 20);
|
||||
g.drawLine(90, 70, 70, 80);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title"); //if comment out, the title would be blank
|
||||
this.setSize(400, 300); //if comment out, the initiated size would be 0
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //if comment out, the program would still running after clicked close button
|
||||
this.setLocationRelativeTo(null); //if comment out, the frame would appear at (0, 0)
|
||||
|
||||
//JButton b1 = new JButton("b1");
|
||||
//JButton b2 = new JButton("b2");
|
||||
this.add(new JButton("b1"), BorderLayout.LINE_START);
|
||||
this.add(new JButton("b2"), BorderLayout.LINE_END);
|
||||
|
||||
/* Only one button appear as Java would detect same button and remove
|
||||
JButton b = new JButton("B1");
|
||||
this.add(b);
|
||||
this.add(b);
|
||||
*/
|
||||
|
||||
/*
|
||||
FlowLayout f1 = new FlowLayout(FlowLayout.LEFT, 20, 40);
|
||||
this.setLayout(f1);
|
||||
*/
|
||||
|
||||
/*
|
||||
GridLayout g1 = new GridLayout(5, 5);
|
||||
this.setLayout(g1);
|
||||
*/
|
||||
//the program presents in 4*2 layout
|
||||
//the program did not use the specified rows and columns, because the lack numbers of components
|
||||
|
||||
BorderLayout bl = new BorderLayout();
|
||||
this.setLayout(bl);
|
||||
|
||||
JLabel l = new JLabel("Enter your name: ");
|
||||
this.add(l, BorderLayout.LINE_START);
|
||||
JTextField tx = new JTextField("Type Text Here");
|
||||
this.add(tx, BorderLayout.CENTER);
|
||||
JCheckBox cb = new JCheckBox("I agree");
|
||||
this.add(cb, BorderLayout.LINE_END);
|
||||
JRadioButton rb = new JRadioButton("Yes");
|
||||
this.add(rb, BorderLayout.AFTER_LINE_ENDS);
|
||||
JComboBox<String> cb1 = new JComboBox<String>(new String[]{"Red", "Green", "Blue"});
|
||||
this.add(cb1, BorderLayout.CENTER);
|
||||
JComboBox<Integer> cb2 = new JComboBox<Integer>(new Integer[]{2, 7, -3, 24});
|
||||
this.add(cb2, BorderLayout.LINE_END);
|
||||
//when add more than one component to one of the five areas of the frame, overlap would occurs
|
||||
//when one area does not contain any components, this area would missing
|
||||
|
||||
//when stretching the window, the components would realign to one row if space permits
|
||||
|
||||
this.setVisible(true); //if comment out, the window would not be visible
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title"); //if comment out, the title would be blank
|
||||
this.setSize(400, 300); //if comment out, the initiated size would be 0
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //if comment out, the program would still running after clicked close button
|
||||
this.setLocationRelativeTo(null); //if comment out, the frame would appear at (0, 0)
|
||||
|
||||
//JButton b1 = new JButton("b1");
|
||||
this.add(new JButton("b1"), BorderLayout.LINE_START);
|
||||
//JButton b2 = new JButton("b2");
|
||||
this.add(new JButton("b2"), BorderLayout.LINE_END);
|
||||
|
||||
/* Only one button appear as Java would detect same button and remove
|
||||
JButton b = new JButton("B1");
|
||||
this.add(b);
|
||||
this.add(b);
|
||||
*/
|
||||
|
||||
/*
|
||||
FlowLayout f1 = new FlowLayout(FlowLayout.LEFT, 20, 40);
|
||||
this.setLayout(f1);
|
||||
*/
|
||||
|
||||
/*
|
||||
GridLayout g1 = new GridLayout(5, 5);
|
||||
this.setLayout(g1);
|
||||
*/
|
||||
//the program presents in 4*2 layout
|
||||
//the program did not use the specified rows and columns, because the lack numbers of components
|
||||
|
||||
BorderLayout bl = new BorderLayout();
|
||||
this.setLayout(bl);
|
||||
|
||||
JLabel l = new JLabel("Enter your name: ");
|
||||
//this.add(l, BorderLayout.LINE_START);
|
||||
JTextField tx = new JTextField("Type Text Here");
|
||||
this.add(tx, BorderLayout.CENTER);
|
||||
JCheckBox cb = new JCheckBox("I agree");
|
||||
//this.add(cb, BorderLayout.LINE_END);
|
||||
JRadioButton rb = new JRadioButton("Yes");
|
||||
this.add(rb, BorderLayout.AFTER_LINE_ENDS);
|
||||
JComboBox<String> cb1 = new JComboBox<String>(new String[]{"Red", "Green", "Blue"});
|
||||
this.add(cb1, BorderLayout.CENTER);
|
||||
JComboBox<Integer> cb2 = new JComboBox<Integer>(new Integer[]{2, 7, -3, 24});
|
||||
this.add(cb2, BorderLayout.LINE_END);
|
||||
|
||||
//when stretching the window, the components would realign to one row if space permits
|
||||
|
||||
this.setVisible(true); //if comment out, the window would not be visible
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title"); //if comment out, the title would be blank
|
||||
this.setSize(400, 300); //if comment out, the initiated size would be 0
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //if comment out, the program would still running after clicked close button
|
||||
this.setLocationRelativeTo(null); //if comment out, the frame would appear at (0, 0)
|
||||
|
||||
this.setLayout((new FlowLayout(FlowLayout.CENTER));
|
||||
|
||||
JPanel p1 = new JPanel();
|
||||
p1.setLayout(new BorderLayout());
|
||||
this.add(p1);
|
||||
p1.setBackground(Color.BLUE);
|
||||
p1.add(new JButton("b1"), BorderLayout.LINE_START);
|
||||
p1.add(new JButton("b2"), BorderLayout.LINE_END);
|
||||
|
||||
JPanel p2 = new JPanel();
|
||||
p2.setLayout(new FlowLayout(FlowLayout.CENTER));
|
||||
this.add(p2);
|
||||
p2.setBackground(Color.GREEN);
|
||||
JLabel l = new JLabel("Enter your name: ");
|
||||
p2.add(l);
|
||||
JTextField tx = new JTextField("Type Text Here");
|
||||
p2.add(tx);
|
||||
|
||||
JPanel p3 = new JPanel();
|
||||
p3.setLayout(new GridLayout(2, 2));
|
||||
this.add(p3);
|
||||
JCheckBox cb = new JCheckBox("I agree");
|
||||
p3.add(cb);
|
||||
JRadioButton rb = new JRadioButton("Yes");
|
||||
p3.add(rb);
|
||||
JComboBox<String> cb1 = new JComboBox<String>(new String[]{"Red", "Green", "Blue"});
|
||||
p3.add(cb1);
|
||||
JComboBox<Integer> cb2 = new JComboBox<Integer>(new Integer[]{2, 7, -3, 24});
|
||||
p3.add(cb2);
|
||||
|
||||
this.setVisible(true); //if comment out, the window would not be visible
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
public class MyPanel {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title"); //if comment out, the title would be blank
|
||||
this.setSize(400, 300); //if comment out, the initiated size would be 0
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //if comment out, the program would still running after clicked close button
|
||||
this.setLocationRelativeTo(null); //if comment out, the frame would appear at (0, 0)
|
||||
|
||||
//JButton b1 = new JButton("b1");
|
||||
this.add(new JButton("b1"), BorderLayout.LINE_START);
|
||||
//JButton b2 = new JButton("b2");
|
||||
this.add(new JButton("b2"), BorderLayout.LINE_END);
|
||||
|
||||
/* Only one button appear as Java would detect same button and remove
|
||||
JButton b = new JButton("B1");
|
||||
this.add(b);
|
||||
this.add(b);
|
||||
*/
|
||||
|
||||
/*
|
||||
FlowLayout f1 = new FlowLayout(FlowLayout.LEFT, 20, 40);
|
||||
this.setLayout(f1);
|
||||
*/
|
||||
|
||||
/*
|
||||
GridLayout g1 = new GridLayout(5, 5);
|
||||
this.setLayout(g1);
|
||||
*/
|
||||
//the program presents in 4*2 layout
|
||||
//the program did not use the specified rows and columns, because the lack numbers of components
|
||||
|
||||
BorderLayout bl = new BorderLayout();
|
||||
this.setLayout(bl);
|
||||
|
||||
JLabel l = new JLabel("Enter your name: ");
|
||||
this.add(l, BorderLayout.LINE_START);
|
||||
JTextField tx = new JTextField("Type Text Here");
|
||||
this.add(tx, BorderLayout.CENTER);
|
||||
JCheckBox cb = new JCheckBox("I agree");
|
||||
this.add(cb, BorderLayout.CENTER);
|
||||
JRadioButton rb = new JRadioButton("Yes");
|
||||
this.add(rb, BorderLayout.CENTER);
|
||||
JComboBox<String> cb1 = new JComboBox<String>(new String[]{"Red", "Green", "Blue"});
|
||||
this.add(cb1, BorderLayout.CENTER);
|
||||
JComboBox<Integer> cb2 = new JComboBox<Integer>(new Integer[]{2, 7, -3, 24});
|
||||
this.add(cb2, BorderLayout.LINE_END);
|
||||
|
||||
//when stretching the window, the components would realign to one row if space permits
|
||||
|
||||
this.setVisible(true); //if comment out, the window would not be visible
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel{
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
g.drawRect(30,10,60,60);
|
||||
g.drawRect(10,20,60,60);
|
||||
g.drawLine(30, 10, 10, 20);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title"); //if comment out, the title would be blank
|
||||
this.setSize(400, 300); //if comment out, the initiated size would be 0
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //if comment out, the program would still running after clicked close button
|
||||
this.setLocationRelativeTo(null); //if comment out, the frame would appear at (0, 0)
|
||||
|
||||
JPanel p1 = new JPanel();
|
||||
p1.setLayout(new BorderLayout());
|
||||
this.add(p1);
|
||||
p1.add(new JButton("b1"), BorderLayout.LINE_START);
|
||||
p1.add(new JButton("b2"), BorderLayout.LINE_END);
|
||||
|
||||
JPanel p2 = new JPanel();
|
||||
p2.setLayout(new FlowLayout(FlowLayout.CENTER));
|
||||
//this.add(p2);
|
||||
JLabel l = new JLabel("Enter your name: ");
|
||||
p2.add(l);
|
||||
JTextField tx = new JTextField("Type Text Here");
|
||||
p2.add(tx);
|
||||
|
||||
JPanel p3 = new JPanel();
|
||||
p3.setLayout(new GridLayout(2, 2));
|
||||
//this.add(p3);
|
||||
JCheckBox cb = new JCheckBox("I agree");
|
||||
p3.add(cb);
|
||||
JRadioButton rb = new JRadioButton("Yes");
|
||||
p3.add(rb);
|
||||
JComboBox<String> cb1 = new JComboBox<String>(new String[]{"Red", "Green", "Blue"});
|
||||
p3.add(cb1);
|
||||
JComboBox<Integer> cb2 = new JComboBox<Integer>(new Integer[]{2, 7, -3, 24});
|
||||
p3.add(cb2);
|
||||
|
||||
this.setVisible(true); //if comment out, the window would not be visible
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title"); //if comment out, the title would be blank
|
||||
this.setSize(400, 300); //if comment out, the initiated size would be 0
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //if comment out, the program would still running after clicked close button
|
||||
this.setLocationRelativeTo(null); //if comment out, the frame would appear at (0, 0)
|
||||
|
||||
JButton b1 = new JButton("b1");
|
||||
this.add(b1);
|
||||
JButton b2 = new JButton("b2");
|
||||
this.add(b2);
|
||||
|
||||
//Only one button appear as Java would detect same button and remove
|
||||
/*
|
||||
JButton b = new JButton("B1");
|
||||
this.add(b);
|
||||
this.add(b);
|
||||
*/
|
||||
|
||||
/*
|
||||
FlowLayout f1 = new FlowLayout(FlowLayout.LEFT, 20, 40);
|
||||
this.setLayout(f1);
|
||||
*/
|
||||
|
||||
GridLayout g1 = new GridLayout(5, 5);
|
||||
this.setLayout(g1);
|
||||
|
||||
JLabel l = new JLabel("Enter your name: ");
|
||||
this.add(l);
|
||||
JTextField tx = new JTextField("Type Text Here");
|
||||
this.add(tx);
|
||||
JCheckBox cb = new JCheckBox("I agree");
|
||||
this.add(cb);
|
||||
JRadioButton rb = new JRadioButton("Yes");
|
||||
this.add(rb);
|
||||
JComboBox<String> cb1 = new JComboBox<String>(new String[]{"Red", "Green", "Blue"});
|
||||
this.add(cb1);
|
||||
JComboBox<Integer> cb2 = new JComboBox<Integer>(new Integer[]{2, 7, -3, 24});
|
||||
this.add(cb2);
|
||||
|
||||
//when stretching the window, the components would realign to one row if space permits
|
||||
|
||||
this.setVisible(true); //if comment out, the window would not be visible
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title"); //if comment out, the title would be blank
|
||||
this.setSize(400, 300); //if comment out, the initiated size would be 0
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //if comment out, the program would still running after clicked close button
|
||||
this.setLocationRelativeTo(null); //if comment out, the frame would appear at (0, 0)
|
||||
|
||||
this.setLayout(new BorderLayout());
|
||||
|
||||
JPanel p1 = new JPanel();
|
||||
p1.setLayout(new BorderLayout());
|
||||
this.add(p1, BorderLayout.LINE_START);
|
||||
p1.setBackground(Color.BLUE);
|
||||
p1.add(new JButton("b1"), BorderLayout.LINE_START);
|
||||
p1.add(new JButton("b2"), BorderLayout.LINE_END);
|
||||
|
||||
JPanel p2 = new JPanel();
|
||||
p2.setLayout(new FlowLayout(FlowLayout.CENTER));
|
||||
this.add(p2, BorderLayout.CENTER);
|
||||
p2.setBackground(Color.GREEN);
|
||||
JLabel l = new JLabel("Enter your name: ");
|
||||
p2.add(l);
|
||||
JTextField tx = new JTextField("Type Text Here");
|
||||
p2.add(tx);
|
||||
|
||||
JPanel p3 = new JPanel();
|
||||
p3.setLayout(new GridLayout(2, 2));
|
||||
this.add(p3, BorderLayout.PAGE_END);
|
||||
JCheckBox cb = new JCheckBox("I agree");
|
||||
p3.add(cb);
|
||||
JRadioButton rb = new JRadioButton("Yes");
|
||||
p3.add(rb);
|
||||
JComboBox<String> cb1 = new JComboBox<String>(new String[]{"Red", "Green", "Blue"});
|
||||
p3.add(cb1);
|
||||
JComboBox<Integer> cb2 = new JComboBox<Integer>(new Integer[]{2, 7, -3, 24});
|
||||
p3.add(cb2);
|
||||
|
||||
this.setVisible(true); //if comment out, the window would not be visible
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title"); //if comment out, the title would be blank
|
||||
this.setSize(400, 300); //if comment out, the initiated size would be 0
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //if comment out, the program would still running after clicked close button
|
||||
this.setLocationRelativeTo(null); //if comment out, the frame would appear at (0, 0)
|
||||
|
||||
this.setLayout(new GridLayout(5, 1));
|
||||
|
||||
JPanel p1 = new JPanel();
|
||||
p1.setLayout(new BorderLayout());
|
||||
this.add(p1);
|
||||
p1.setBackground(Color.BLUE);
|
||||
p1.add(new JButton("b1"), BorderLayout.LINE_START);
|
||||
p1.add(new JButton("b2"), BorderLayout.LINE_END);
|
||||
|
||||
JPanel p2 = new JPanel();
|
||||
p2.setLayout(new FlowLayout(FlowLayout.CENTER));
|
||||
this.add(p2);
|
||||
p2.setBackground(Color.GREEN);
|
||||
JLabel l = new JLabel("Enter your name: ");
|
||||
p2.add(l);
|
||||
JTextField tx = new JTextField("Type Text Here");
|
||||
p2.add(tx);
|
||||
|
||||
JPanel p3 = new JPanel();
|
||||
p3.setLayout(new GridLayout(2, 2));
|
||||
this.add(p3);
|
||||
JCheckBox cb = new JCheckBox("I agree");
|
||||
p3.add(cb);
|
||||
JRadioButton rb = new JRadioButton("Yes");
|
||||
p3.add(rb);
|
||||
JComboBox<String> cb1 = new JComboBox<String>(new String[]{"Red", "Green", "Blue"});
|
||||
p3.add(cb1);
|
||||
JComboBox<Integer> cb2 = new JComboBox<Integer>(new Integer[]{2, 7, -3, 24});
|
||||
p3.add(cb2);
|
||||
|
||||
this.setVisible(true); //if comment out, the window would not be visible
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title"); //if comment out, the title would be blank
|
||||
this.setSize(400, 300); //if comment out, the initiated size would be 0
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //if comment out, the program would still running after clicked close button
|
||||
this.setLocationRelativeTo(null); //if comment out, the frame would appear at (0, 0)
|
||||
|
||||
//JButton b1 = new JButton("b1");
|
||||
//JButton b2 = new JButton("b2");
|
||||
this.add(new JButton("b1"), BorderLayout.LINE_START);
|
||||
this.add(new JButton("b2"), BorderLayout.LINE_END);
|
||||
|
||||
/* Only one button appear as Java would detect same button and remove
|
||||
JButton b = new JButton("B1");
|
||||
this.add(b);
|
||||
this.add(b);
|
||||
*/
|
||||
|
||||
/*
|
||||
FlowLayout f1 = new FlowLayout(FlowLayout.LEFT, 20, 40);
|
||||
this.setLayout(f1);
|
||||
*/
|
||||
|
||||
/*
|
||||
GridLayout g1 = new GridLayout(5, 5);
|
||||
this.setLayout(g1);
|
||||
*/
|
||||
//the program presents in 4*2 layout
|
||||
//the program did not use the specified rows and columns, because the lack numbers of components
|
||||
|
||||
BorderLayout bl = new BorderLayout();
|
||||
this.setLayout(bl);
|
||||
|
||||
JLabel l = new JLabel("Enter your name: ");
|
||||
this.add(l, BorderLayout.LINE_START);
|
||||
JTextField tx = new JTextField("Type Text Here");
|
||||
this.add(tx, BorderLayout.CENTER);
|
||||
JCheckBox cb = new JCheckBox("I agree");
|
||||
this.add(cb, BorderLayout.LINE_END);
|
||||
JRadioButton rb = new JRadioButton("Yes");
|
||||
this.add(rb, BorderLayout.AFTER_LINE_ENDS);
|
||||
JComboBox<String> cb1 = new JComboBox<String>(new String[]{"Red", "Green", "Blue"});
|
||||
this.add(cb1, BorderLayout.CENTER);
|
||||
JComboBox<Integer> cb2 = new JComboBox<Integer>(new Integer[]{2, 7, -3, 24});
|
||||
this.add(cb2, BorderLayout.LINE_END);
|
||||
|
||||
//when stretching the window, the components would realign to one row if space permits
|
||||
|
||||
this.setVisible(true); //if comment out, the window would not be visible
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
|
||||
public class Start {
|
||||
|
||||
public static void main(String[] args) {
|
||||
javax.swing.SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
new MyFrame();
|
||||
new MyFrame();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title"); //if comment out, the title would be blank
|
||||
this.setSize(400, 300); //if comment out, the initiated size would be 0
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //if comment out, the program would still running after clicked close button
|
||||
this.setLocationRelativeTo(null); //if comment out, the frame would appear at (0, 0)
|
||||
|
||||
this.add(new MyPanel());
|
||||
|
||||
this.setVisible(true); //if comment out, the window would not be visible
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel{
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
g.drawRect(30,10,60,60);
|
||||
g.drawRect(10,20,60,60);
|
||||
g.drawLine(30, 10, 10, 20);
|
||||
g.drawLine(90, 70, 70, 80);
|
||||
g.drawLine(90, 10, 70, 20);
|
||||
g.drawLine(30, 70, 10, 80);
|
||||
|
||||
g.setColor(Color.BLUE);
|
||||
g.drawOval(120, 10, 60, 15);
|
||||
g.drawOval(120, 70, 60, 15);
|
||||
g.drawLine(120, 20, 120, 80);
|
||||
g.drawLine(180, 20, 180, 80);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title"); //if comment out, the title would be blank
|
||||
this.setSize(400, 300); //if comment out, the initiated size would be 0
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //if comment out, the program would still running after clicked close button
|
||||
this.setLocationRelativeTo(null); //if comment out, the frame would appear at (0, 0)
|
||||
|
||||
JButton b1 = new JButton("b1");
|
||||
this.add(b1);
|
||||
JButton b2 = new JButton("b2");
|
||||
this.add(b2);
|
||||
|
||||
/* Only one button appear as Java would detect same button and remove
|
||||
JButton b = new JButton("B1");
|
||||
this.add(b);
|
||||
this.add(b);
|
||||
*/
|
||||
|
||||
/*
|
||||
FlowLayout f1 = new FlowLayout(FlowLayout.LEFT, 20, 40);
|
||||
this.setLayout(f1);
|
||||
*/
|
||||
|
||||
GridLayout g1 = new GridLayout(5, 5);
|
||||
this.setLayout(g1);
|
||||
|
||||
JLabel l = new JLabel("Enter your name: ");
|
||||
this.add(l);
|
||||
JTextField tx = new JTextField("Type Text Here");
|
||||
this.add(tx);
|
||||
JCheckBox cb = new JCheckBox("I agree");
|
||||
this.add(cb);
|
||||
JRadioButton rb = new JRadioButton("Yes");
|
||||
this.add(rb);
|
||||
JComboBox<String> cb1 = new JComboBox<String>(new String[]{"Red", "Green", "Blue"});
|
||||
this.add(cb1);
|
||||
JComboBox<Integer> cb2 = new JComboBox<Integer>(new Integer[]{2, 7, -3, 24});
|
||||
this.add(cb2);
|
||||
|
||||
//when stretching the window, the components would realign to one row if space permits
|
||||
|
||||
this.setVisible(true); //if comment out, the window would not be visible
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title"); //if comment out, the title would be blank
|
||||
this.setSize(400, 300); //if comment out, the initiated size would be 0
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //if comment out, the program would still running after clicked close button
|
||||
this.setLocationRelativeTo(null); //if comment out, the frame would appear at (0, 0)
|
||||
|
||||
JPanel p1 = new JPanel();
|
||||
BorderLayout bl = new BorderLayout();
|
||||
p1.setLayout(bl);
|
||||
p1.add(new JButton("b1"), BorderLayout.LINE_START);
|
||||
p1.add(new JButton("b2"), BorderLayout.LINE_END);
|
||||
|
||||
JPanel p2 = new JPanel();
|
||||
FlowLayout f1 = new FlowLayout(FlowLayout.CENTER);
|
||||
p2.setLayout(f1);
|
||||
JLabel l = new JLabel("Enter your name: ");
|
||||
p2.add(l);
|
||||
JTextField tx = new JTextField("Type Text Here");
|
||||
p2.add(tx);
|
||||
|
||||
JPanel p3 = new JPanel();
|
||||
GridLayout g1 = new GridLayout(2, 2);
|
||||
p3.setLayout(g1);
|
||||
JCheckBox cb = new JCheckBox("I agree");
|
||||
this.add(cb);
|
||||
JRadioButton rb = new JRadioButton("Yes");
|
||||
this.add(rb);
|
||||
JComboBox<String> cb1 = new JComboBox<String>(new String[]{"Red", "Green", "Blue"});
|
||||
this.add(cb1);
|
||||
JComboBox<Integer> cb2 = new JComboBox<Integer>(new Integer[]{2, 7, -3, 24});
|
||||
this.add(cb2);
|
||||
|
||||
this.setVisible(true); //if comment out, the window would not be visible
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel{
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
g.drawRect(30,10,60,60);
|
||||
g.drawRect(10,20,60,60);
|
||||
g.drawLine(30, 10, 10, 20);
|
||||
g.drawLine(90, 70, 70, 80);
|
||||
g.drawLine(90, 10, 70, 20);
|
||||
g.drawLine(30, 70, 10, 80);
|
||||
|
||||
g.setColor(Color.BLUE);
|
||||
g.drawOval(120, 10, 30, 10);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel{
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.BLUE);
|
||||
//g.drawString("hello",20, 80);
|
||||
g.drawString("hello",
|
||||
(int)Math.round(Math.random() * this.getWidth()),
|
||||
(int)Math.round(Math.random() * this.getHeight()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title"); //if comment out, the title would be blank
|
||||
this.setSize(400, 300); //if comment out, the initiated size would be 0
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //if comment out, the program would still running after clicked close button
|
||||
this.setLocationRelativeTo(null); //if comment out, the frame would appear at (0, 0)
|
||||
|
||||
JButton b1 = new JButton("b1");
|
||||
this.add(b1);
|
||||
JButton b2 = new JButton("b2");
|
||||
this.add(b2);
|
||||
|
||||
/* Only one button appear as Java would detect same button and remove
|
||||
JButton b = new JButton("B1");
|
||||
this.add(b);
|
||||
this.add(b);
|
||||
*/
|
||||
|
||||
FlowLayout f1 = new FlowLayout(FlowLayout.LEFT, 20, 40);
|
||||
this.setLayout(f1);
|
||||
|
||||
this.setVisible(true); //if comment out, the window would not be visible
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel{
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
g.drawRect(30,10,60,60);
|
||||
g.drawRect(10,20,60,60);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title"); //if comment out, the title would be blank
|
||||
this.setSize(400, 300); //if comment out, the initiated size would be 0
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //if comment out, the program would still running after clicked close button
|
||||
this.setLocationRelativeTo(null); //if comment out, the frame would appear at (0, 0)
|
||||
|
||||
this.setLayout(new GridLayout(3, 2));
|
||||
|
||||
JPanel p1 = new JPanel();
|
||||
p1.setLayout(new BorderLayout());
|
||||
this.add(p1);
|
||||
p1.setBackground(Color.BLUE);
|
||||
p1.add(new JButton("b1"), BorderLayout.LINE_START);
|
||||
p1.add(new JButton("b2"), BorderLayout.LINE_END);
|
||||
|
||||
JPanel p2 = new JPanel();
|
||||
p2.setLayout(new FlowLayout(FlowLayout.CENTER));
|
||||
this.add(p2);
|
||||
p2.setBackground(Color.GREEN);
|
||||
JLabel l = new JLabel("Enter your name: ");
|
||||
p2.add(l);
|
||||
JTextField tx = new JTextField("Type Text Here");
|
||||
p2.add(tx);
|
||||
|
||||
JPanel p3 = new JPanel();
|
||||
p3.setLayout(new GridLayout(2, 2));
|
||||
this.add(p3);
|
||||
JCheckBox cb = new JCheckBox("I agree");
|
||||
p3.add(cb);
|
||||
JRadioButton rb = new JRadioButton("Yes");
|
||||
p3.add(rb);
|
||||
JComboBox<String> cb1 = new JComboBox<String>(new String[]{"Red", "Green", "Blue"});
|
||||
p3.add(cb1);
|
||||
JComboBox<Integer> cb2 = new JComboBox<Integer>(new Integer[]{2, 7, -3, 24});
|
||||
p3.add(cb2);
|
||||
|
||||
this.setVisible(true); //if comment out, the window would not be visible
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel{
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.BLUE);
|
||||
//g.drawString("hello",20, 80);
|
||||
g.drawString("hello",
|
||||
(int)Math.round(Math.random() * this.getWidth()),
|
||||
(int)Math.round(Math.random() * this.getHeight()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title"); //if comment out, the title would be blank
|
||||
this.setSize(400, 300); //if comment out, the initiated size would be 0
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //if comment out, the program would still running after clicked close button
|
||||
this.setLocationRelativeTo(null); //if comment out, the frame would appear at (0, 0)
|
||||
|
||||
JButton b1 = new JButton("b1");
|
||||
this.add(b1);
|
||||
JButton b2 = new JButton("b2");
|
||||
this.add(b2);
|
||||
|
||||
/*
|
||||
//Only one button appear as Java would detect same button and remove
|
||||
JButton b = new JButton("B1");
|
||||
this.add(b);
|
||||
this.add(b);
|
||||
*/
|
||||
|
||||
/*
|
||||
FlowLayout f1 = new FlowLayout(FlowLayout.LEFT, 20, 40);
|
||||
this.setLayout(f1);
|
||||
*/
|
||||
|
||||
GridLayout g1 = new GridLayout(5, 5);
|
||||
this.setLayout(g1);
|
||||
|
||||
JLabel l = new JLabel("Enter your name: ");
|
||||
this.add(l);
|
||||
JTextField tx = new JTextField("Type Text Here");
|
||||
this.add(tx);
|
||||
JCheckBox cb = new JCheckBox("I agree");
|
||||
this.add(cb);
|
||||
JRadioButton rb = new JRadioButton("Yes");
|
||||
this.add(rb);
|
||||
JComboBox<String> cb1 = new JComboBox<String>(new String[]{"Red", "Green", "Blue"});
|
||||
this.add(cb1);
|
||||
JComboBox<Integer> cb2 = new JComboBox<Integer>(new Integer[]{2, 7, -3, 24});
|
||||
this.add(cb2);
|
||||
|
||||
//when stretching the window, the components would realign to one row if space permits
|
||||
|
||||
this.setVisible(true); //if comment out, the window would not be visible
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title"); //if comment out, the title would be blank
|
||||
this.setSize(400, 300); //if comment out, the initiated size would be 0
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //if comment out, the program would still running after clicked close button
|
||||
this.setLocationRelativeTo(null); //if comment out, the frame would appear at (0, 0)
|
||||
|
||||
JButton b1 = new JButton("b1");
|
||||
this.add(b1);
|
||||
JButton b2 = new JButton("b2");
|
||||
this.add(b2);
|
||||
|
||||
/* Only one button appear as Java would detect same button and remove
|
||||
JButton b = new JButton("B1");
|
||||
this.add(b);
|
||||
this.add(b);
|
||||
*/
|
||||
|
||||
/*
|
||||
FlowLayout f1 = new FlowLayout(FlowLayout.LEFT, 20, 40);
|
||||
this.setLayout(f1);
|
||||
*/
|
||||
|
||||
/*
|
||||
GridLayout g1 = new GridLayout(5, 5);
|
||||
this.setLayout(g1);
|
||||
*/
|
||||
//the program presents in 4*2 layout
|
||||
//the program did not use the specified rows and columns, because the lack numbers of components
|
||||
|
||||
BorderLayout bl = new BorderLayout();
|
||||
this.setLayout(bl);
|
||||
|
||||
JLabel l = new JLabel("Enter your name: ");
|
||||
this.add(l);
|
||||
JTextField tx = new JTextField("Type Text Here");
|
||||
this.add(tx);
|
||||
JCheckBox cb = new JCheckBox("I agree");
|
||||
this.add(cb);
|
||||
JRadioButton rb = new JRadioButton("Yes");
|
||||
this.add(rb);
|
||||
JComboBox<String> cb1 = new JComboBox<String>(new String[]{"Red", "Green", "Blue"});
|
||||
this.add(cb1);
|
||||
JComboBox<Integer> cb2 = new JComboBox<Integer>(new Integer[]{2, 7, -3, 24});
|
||||
this.add(cb2);
|
||||
|
||||
//when stretching the window, the components would realign to one row if space permits
|
||||
|
||||
this.setVisible(true); //if comment out, the window would not be visible
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title"); //if comment out, the title would be blank
|
||||
this.setSize(400, 300); //if comment out, the initiated size would be 0
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //if comment out, the program would still running after clicked close button
|
||||
this.setLocationRelativeTo(null); //if comment out, the frame would appear at (0, 0)
|
||||
|
||||
this.setLayout(new GridLayout(3, 1));
|
||||
|
||||
JPanel p1 = new JPanel();
|
||||
p1.setLayout(new BorderLayout());
|
||||
this.add(p1);
|
||||
p1.setBackground(Color.BLUE);
|
||||
p1.add(new JButton("b1"), BorderLayout.LINE_START);
|
||||
p1.add(new JButton("b2"), BorderLayout.LINE_END);
|
||||
|
||||
JPanel p2 = new JPanel();
|
||||
p2.setLayout(new FlowLayout(FlowLayout.CENTER));
|
||||
this.add(p2);
|
||||
p2.setBackground(Color.GREEN);
|
||||
JLabel l = new JLabel("Enter your name: ");
|
||||
p2.add(l);
|
||||
JTextField tx = new JTextField("Type Text Here");
|
||||
p2.add(tx);
|
||||
|
||||
JPanel p3 = new JPanel();
|
||||
p3.setLayout(new GridLayout(2, 2));
|
||||
this.add(p3);
|
||||
JCheckBox cb = new JCheckBox("I agree");
|
||||
p3.add(cb);
|
||||
JRadioButton rb = new JRadioButton("Yes");
|
||||
p3.add(rb);
|
||||
JComboBox<String> cb1 = new JComboBox<String>(new String[]{"Red", "Green", "Blue"});
|
||||
p3.add(cb1);
|
||||
JComboBox<Integer> cb2 = new JComboBox<Integer>(new Integer[]{2, 7, -3, 24});
|
||||
p3.add(cb2);
|
||||
|
||||
this.setVisible(true); //if comment out, the window would not be visible
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title"); //if comment out, the title would be blank
|
||||
this.setSize(400, 300); //if comment out, the initiated size would be 0
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //if comment out, the program would still running after clicked close button
|
||||
this.setLocationRelativeTo(null); //if comment out, the frame would appear at (0, 0)
|
||||
|
||||
//JButton b1 = new JButton("b1");
|
||||
//JButton b2 = new JButton("b2");
|
||||
this.add(new JButton("b1"), BorderLayout.PAGE_START);
|
||||
this.add(new JButton("b2"), BorderLayout.PAGE_END);
|
||||
|
||||
/* Only one button appear as Java would detect same button and remove
|
||||
JButton b = new JButton("B1");
|
||||
this.add(b);
|
||||
this.add(b);
|
||||
*/
|
||||
|
||||
/*
|
||||
FlowLayout f1 = new FlowLayout(FlowLayout.LEFT, 20, 40);
|
||||
this.setLayout(f1);
|
||||
*/
|
||||
|
||||
/*
|
||||
GridLayout g1 = new GridLayout(5, 5);
|
||||
this.setLayout(g1);
|
||||
*/
|
||||
//the program presents in 4*2 layout
|
||||
//the program did not use the specified rows and columns, because the lack numbers of components
|
||||
|
||||
BorderLayout bl = new BorderLayout();
|
||||
this.setLayout(bl);
|
||||
|
||||
JLabel l = new JLabel("Enter your name: ");
|
||||
this.add(l, BorderLayout.LINE_START);
|
||||
JTextField tx = new JTextField("Type Text Here");
|
||||
this.add(tx, BorderLayout.CENTER);
|
||||
JCheckBox cb = new JCheckBox("I agree");
|
||||
this.add(cb, BorderLayout.LINE_END);
|
||||
JRadioButton rb = new JRadioButton("Yes");
|
||||
this.add(rb, BorderLayout.AFTER_LINE_ENDS);
|
||||
JComboBox<String> cb1 = new JComboBox<String>(new String[]{"Red", "Green", "Blue"});
|
||||
this.add(cb1, BorderLayout.CENTER);
|
||||
JComboBox<Integer> cb2 = new JComboBox<Integer>(new Integer[]{2, 7, -3, 24});
|
||||
this.add(cb2, BorderLayout.LINE_END);
|
||||
|
||||
//when stretching the window, the components would realign to one row if space permits
|
||||
|
||||
this.setVisible(true); //if comment out, the window would not be visible
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel{
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
g.drawRect(20,20,60,60);
|
||||
g.drawRect(10,30,60,60);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title"); //if comment out, the title would be blank
|
||||
this.setSize(400, 300); //if comment out, the initiated size would be 0
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //if comment out, the program would still running after clicked close button
|
||||
this.setLocationRelativeTo(null); //if comment out, the frame would appear at (0, 0)
|
||||
|
||||
JButton b1 = new JButton("b1");
|
||||
JButton b2 = new JButton("b2");
|
||||
this.add(new JButton("b1"), BorderLayout.LINE_START);
|
||||
this.add(new JButton("b2"), BorderLayout.LINE_END);
|
||||
|
||||
/* Only one button appear as Java would detect same button and remove
|
||||
JButton b = new JButton("B1");
|
||||
this.add(b);
|
||||
this.add(b);
|
||||
*/
|
||||
|
||||
/*
|
||||
FlowLayout f1 = new FlowLayout(FlowLayout.LEFT, 20, 40);
|
||||
this.setLayout(f1);
|
||||
*/
|
||||
|
||||
/*
|
||||
GridLayout g1 = new GridLayout(5, 5);
|
||||
this.setLayout(g1);
|
||||
*/
|
||||
//the program presents in 4*2 layout
|
||||
//the program did not use the specified rows and columns, because the lack numbers of components
|
||||
|
||||
BorderLayout bl = new BorderLayout();
|
||||
this.setLayout(bl);
|
||||
|
||||
JLabel l = new JLabel("Enter your name: ");
|
||||
this.add(l, BorderLayout.LINE_START);
|
||||
JTextField tx = new JTextField("Type Text Here");
|
||||
this.add(tx, BorderLayout.CENTER);
|
||||
JCheckBox cb = new JCheckBox("I agree");
|
||||
this.add(cb, BorderLayout.LINE_END);
|
||||
JRadioButton rb = new JRadioButton("Yes");
|
||||
this.add(rb, BorderLayout.AFTER_LINE_ENDS);
|
||||
JComboBox<String> cb1 = new JComboBox<String>(new String[]{"Red", "Green", "Blue"});
|
||||
this.add(cb1, BorderLayout.CENTER);
|
||||
JComboBox<Integer> cb2 = new JComboBox<Integer>(new Integer[]{2, 7, -3, 24});
|
||||
this.add(cb2, BorderLayout.LINE_END);
|
||||
|
||||
//when stretching the window, the components would realign to one row if space permits
|
||||
|
||||
this.setVisible(true); //if comment out, the window would not be visible
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title");
|
||||
this.setSize(400, 300);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setLocationRelativeTo(null);
|
||||
|
||||
//JButton b1 = new JButton("b1");
|
||||
this.add(new JButton("b1"), BorderLayout.LINE_START);
|
||||
//JButton b2 = new JButton("b2");
|
||||
this.add(new JButton("b2"), BorderLayout.LINE_END);
|
||||
|
||||
/* Only one button appear as Java would detect same button and remove
|
||||
JButton b = new JButton("B1");
|
||||
this.add(b);
|
||||
this.add(b);
|
||||
*/
|
||||
|
||||
/*
|
||||
FlowLayout f1 = new FlowLayout(FlowLayout.LEFT, 20, 40);
|
||||
this.setLayout(f1);
|
||||
*/
|
||||
|
||||
/*
|
||||
GridLayout g1 = new GridLayout(5, 5);
|
||||
this.setLayout(g1);
|
||||
*/
|
||||
//the program presents in 4*2 layout
|
||||
//the program did not use the specified rows and columns, because the lack numbers of components
|
||||
//the layout did not changed as the components are already parallel-aligned
|
||||
//if set number of rows = 0, it would aligned in one row
|
||||
|
||||
BorderLayout bl = new BorderLayout();
|
||||
this.setLayout(bl);
|
||||
|
||||
JLabel l = new JLabel("Enter your name: ");
|
||||
this.add(l, BorderLayout.LINE_START);
|
||||
JTextField tx = new JTextField("Type Text Here");
|
||||
this.add(tx, BorderLayout.CENTER);
|
||||
JCheckBox cb = new JCheckBox("I agree");
|
||||
this.add(cb, BorderLayout.LINE_END);
|
||||
JRadioButton rb = new JRadioButton("Yes");
|
||||
this.add(rb, BorderLayout.AFTER_LINE_ENDS);
|
||||
JComboBox<String> cb1 = new JComboBox<String>(new String[]{"Red", "Green", "Blue"});
|
||||
this.add(cb1, BorderLayout.CENTER);
|
||||
JComboBox<Integer> cb2 = new JComboBox<Integer>(new Integer[]{2, 7, -3, 24});
|
||||
this.add(cb2, BorderLayout.LINE_END);
|
||||
//when add more than one component to one of the five areas of the frame, overlap would occurs
|
||||
//when one area does not contain any components, this area would missing
|
||||
|
||||
this.setVisible(true);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title"); //if comment out, the title would be blank
|
||||
this.setSize(400, 300); //if comment out, the initiated size would be 0
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //if comment out, the program would still running after clicked close button
|
||||
this.setLocationRelativeTo(null); //if comment out, the frame would appear at (0, 0)
|
||||
|
||||
//JButton b1 = new JButton("b1");
|
||||
this.add(new JButton("b1"), BorderLayout.LINE_START);
|
||||
//JButton b2 = new JButton("b2");
|
||||
this.add(new JButton("b2"), BorderLayout.LINE_END);
|
||||
|
||||
/* Only one button appear as Java would detect same button and remove
|
||||
JButton b = new JButton("B1");
|
||||
this.add(b);
|
||||
this.add(b);
|
||||
*/
|
||||
|
||||
/*
|
||||
FlowLayout f1 = new FlowLayout(FlowLayout.LEFT, 20, 40);
|
||||
this.setLayout(f1);
|
||||
*/
|
||||
|
||||
/*
|
||||
GridLayout g1 = new GridLayout(5, 5);
|
||||
this.setLayout(g1);
|
||||
*/
|
||||
//the program presents in 4*2 layout
|
||||
//the program did not use the specified rows and columns, because the lack numbers of components
|
||||
|
||||
BorderLayout bl = new BorderLayout();
|
||||
this.setLayout(bl);
|
||||
|
||||
JLabel l = new JLabel("Enter your name: ");
|
||||
this.add(l);
|
||||
JTextField tx = new JTextField("Type Text Here");
|
||||
this.add(tx);
|
||||
JCheckBox cb = new JCheckBox("I agree");
|
||||
this.add(cb);
|
||||
JRadioButton rb = new JRadioButton("Yes");
|
||||
this.add(rb);
|
||||
JComboBox<String> cb1 = new JComboBox<String>(new String[]{"Red", "Green", "Blue"});
|
||||
this.add(cb1);
|
||||
JComboBox<Integer> cb2 = new JComboBox<Integer>(new Integer[]{2, 7, -3, 24});
|
||||
this.add(cb2);
|
||||
|
||||
//when stretching the window, the components would realign to one row if space permits
|
||||
|
||||
this.setVisible(true); //if comment out, the window would not be visible
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel{
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
g.drawRect(30,30,60,60);
|
||||
g.drawRect(10,30,60,60);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel{
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.BLUE);
|
||||
//g.drawString("hello",20, 80);
|
||||
g.drawString("hello",
|
||||
(int)Math.round(Math.random() * this.getWidth()),
|
||||
(int)Math.round(Math.random() * this.getHeight()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title"); //if comment out, the title would be blank
|
||||
this.setSize(400, 300); //if comment out, the initiated size would be 0
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //if comment out, the program would still running after clicked close button
|
||||
this.setLocationRelativeTo(null); //if comment out, the frame would appear at (0, 0)
|
||||
|
||||
//JButton b1 = new JButton("b1");
|
||||
this.add(new JButton("b1"), BorderLayout.LINE_START);
|
||||
//JButton b2 = new JButton("b2");
|
||||
this.add(new JButton("b2"), BorderLayout.LINE_END);
|
||||
|
||||
/* Only one button appear as Java would detect same button and remove
|
||||
JButton b = new JButton("B1");
|
||||
this.add(b);
|
||||
this.add(b);
|
||||
*/
|
||||
|
||||
/*
|
||||
FlowLayout f1 = new FlowLayout(FlowLayout.LEFT, 20, 40);
|
||||
this.setLayout(f1);
|
||||
*/
|
||||
|
||||
/*
|
||||
GridLayout g1 = new GridLayout(5, 5);
|
||||
this.setLayout(g1);
|
||||
*/
|
||||
//the program presents in 4*2 layout
|
||||
//the program did not use the specified rows and columns, because the lack numbers of components
|
||||
|
||||
BorderLayout bl = new BorderLayout();
|
||||
this.setLayout(bl);
|
||||
|
||||
JLabel l = new JLabel("Enter your name: ");
|
||||
this.add(l, BorderLayout.LINE_START);
|
||||
JTextField tx = new JTextField("Type Text Here");
|
||||
this.add(tx, BorderLayout.CENTER);
|
||||
JCheckBox cb = new JCheckBox("I agree");
|
||||
this.add(cb, BorderLayout.LINE_END);
|
||||
JRadioButton rb = new JRadioButton("Yes");
|
||||
this.add(rb, BorderLayout.AFTER_LINE_ENDS);
|
||||
JComboBox<String> cb1 = new JComboBox<String>(new String[]{"Red", "Green", "Blue"});
|
||||
this.add(cb1, BorderLayout.CENTER);
|
||||
JComboBox<Integer> cb2 = new JComboBox<Integer>(new Integer[]{2, 7, -3, 24});
|
||||
this.add(cb2, BorderLayout.LINE_END);
|
||||
|
||||
//when stretching the window, the components would realign to one row if space permits
|
||||
|
||||
this.setVisible(true); //if comment out, the window would not be visible
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title"); //if comment out, the title would be blank
|
||||
this.setSize(400, 300); //if comment out, the initiated size would be 0
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //if comment out, the program would still running after clicked close button
|
||||
this.setLocationRelativeTo(null); //if comment out, the frame would appear at (0, 0)
|
||||
|
||||
this.setLayout(new GridLayout(3, 1));
|
||||
|
||||
JPanel p1 = new JPanel();
|
||||
p1.setLayout(new BorderLayout());
|
||||
this.add(p1);
|
||||
p1.add(new JButton("b1"), BorderLayout.LINE_START);
|
||||
p1.add(new JButton("b2"), BorderLayout.LINE_END);
|
||||
|
||||
JPanel p2 = new JPanel();
|
||||
p2.setLayout(new FlowLayout(FlowLayout.CENTER));
|
||||
this.add(p2);
|
||||
JLabel l = new JLabel("Enter your name: ");
|
||||
p2.add(l);
|
||||
JTextField tx = new JTextField("Type Text Here");
|
||||
p2.add(tx);
|
||||
|
||||
JPanel p3 = new JPanel();
|
||||
p3.setLayout(new GridLayout(2, 2));
|
||||
this.add(p3);
|
||||
JCheckBox cb = new JCheckBox("I agree");
|
||||
p3.add(cb);
|
||||
JRadioButton rb = new JRadioButton("Yes");
|
||||
p3.add(rb);
|
||||
JComboBox<String> cb1 = new JComboBox<String>(new String[]{"Red", "Green", "Blue"});
|
||||
p3.add(cb1);
|
||||
JComboBox<Integer> cb2 = new JComboBox<Integer>(new Integer[]{2, 7, -3, 24});
|
||||
p3.add(cb2);
|
||||
|
||||
this.setVisible(true); //if comment out, the window would not be visible
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title"); //if comment out, the title would be blank
|
||||
this.setSize(400, 300); //if comment out, the initiated size would be 0
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //if comment out, the program would still running after clicked close button
|
||||
this.setLocationRelativeTo(null); //if comment out, the frame would appear at (0, 0)
|
||||
|
||||
//JButton b1 = new JButton("b1");
|
||||
//JButton b2 = new JButton("b2");
|
||||
this.add(new JButton("b1"), BorderLayout.LINE_START);
|
||||
//this.add(new JButton("b2"), BorderLayout.LINE_END);
|
||||
|
||||
/* Only one button appear as Java would detect same button and remove
|
||||
JButton b = new JButton("B1");
|
||||
this.add(b);
|
||||
this.add(b);
|
||||
*/
|
||||
|
||||
/*
|
||||
FlowLayout f1 = new FlowLayout(FlowLayout.LEFT, 20, 40);
|
||||
this.setLayout(f1);
|
||||
*/
|
||||
|
||||
/*
|
||||
GridLayout g1 = new GridLayout(5, 5);
|
||||
this.setLayout(g1);
|
||||
*/
|
||||
//the program presents in 4*2 layout
|
||||
//the program did not use the specified rows and columns, because the lack numbers of components
|
||||
|
||||
BorderLayout bl = new BorderLayout();
|
||||
this.setLayout(bl);
|
||||
|
||||
JLabel l = new JLabel("Enter your name: ");
|
||||
this.add(l, BorderLayout.LINE_START);
|
||||
JTextField tx = new JTextField("Type Text Here");
|
||||
this.add(tx, BorderLayout.CENTER);
|
||||
JCheckBox cb = new JCheckBox("I agree");
|
||||
//this.add(cb, BorderLayout.LINE_END);
|
||||
JRadioButton rb = new JRadioButton("Yes");
|
||||
//this.add(rb, BorderLayout.AFTER_LINE_ENDS);
|
||||
JComboBox<String> cb1 = new JComboBox<String>(new String[]{"Red", "Green", "Blue"});
|
||||
this.add(cb1, BorderLayout.CENTER);
|
||||
JComboBox<Integer> cb2 = new JComboBox<Integer>(new Integer[]{2, 7, -3, 24});
|
||||
//this.add(cb2, BorderLayout.LINE_END);
|
||||
//when add more than one component to one of the five areas of the frame, overlap would occurs
|
||||
|
||||
//when stretching the window, the components would realign to one row if space permits
|
||||
|
||||
this.setVisible(true); //if comment out, the window would not be visible
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel{
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
g.drawRect(30,10,60,60);
|
||||
g.drawRect(10,20,60,60);
|
||||
g.drawLine(30, 10, 10, 20);
|
||||
g.drawLine(90, 70, 70, 80);
|
||||
g.drawLine(90, 10, 70, 20);
|
||||
g.drawLine(30, 70, 10, 80);
|
||||
|
||||
g.setColor(Color.BLUE);
|
||||
g.drawOval(120, 10, 60, 15);
|
||||
g.drawOval(120, 70, 60, 15);
|
||||
g.drawLine(120, 10, 120, 70);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel{
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
g.drawRect(30,10,60,60);
|
||||
g.drawRect(10,20,60,60);
|
||||
g.drawLine(30, 10, 10, 20);
|
||||
g.drawLine(90, 70, 70, 80);
|
||||
g.drawLine(90, 10, 70, 20);
|
||||
g.drawLine(30, 70, 10, 80);
|
||||
|
||||
g.setColor(Color.BLUE);
|
||||
g.drawOval(120, 10, 60, 15);
|
||||
g.drawOval(120, 70, 60, 15);
|
||||
g.drawLine(120, 17, 120, 77);
|
||||
g.drawLine(180, 27, 180, 80);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel{
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
g.drawRect(30,10,60,60);
|
||||
g.drawRect(10,20,60,60);
|
||||
g.drawLine(30, 10, 10, 20);
|
||||
g.drawLine(90, 70, 70, 80);
|
||||
g.drawLine(90, 10, 70, 20);
|
||||
g.drawLine(30, 70, 10, 80);
|
||||
|
||||
g.setColor(Color.BLUE);
|
||||
g.drawOval(120, 10, 60, 15);
|
||||
g.drawOval(120, 70, 60, 15);
|
||||
g.drawLine(120, 15, 120, 75);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title"); //if comment out, the title would be blank
|
||||
this.setSize(400, 300); //if comment out, the initiated size would be 0
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //if comment out, the program would still running after clicked close button
|
||||
this.setLocationRelativeTo(null); //if comment out, the frame would appear at (0, 0)
|
||||
|
||||
this.setLayout(new BorderLayout());
|
||||
|
||||
JPanel p1 = new JPanel();
|
||||
p1.setLayout(new BorderLayout());
|
||||
this.add(p1, BorderLayout.PAGE_START);
|
||||
p1.setBackground(Color.BLUE);
|
||||
p1.add(new JButton("b1"), BorderLayout.LINE_START);
|
||||
p1.add(new JButton("b2"), BorderLayout.LINE_END);
|
||||
|
||||
JPanel p2 = new JPanel();
|
||||
p2.setLayout(new FlowLayout(FlowLayout.CENTER));
|
||||
this.add(p2, BorderLayout.CENTER);
|
||||
p2.setBackground(Color.GREEN);
|
||||
JLabel l = new JLabel("Enter your name: ");
|
||||
p2.add(l);
|
||||
JTextField tx = new JTextField("Type Text Here");
|
||||
p2.add(tx);
|
||||
|
||||
JPanel p3 = new JPanel();
|
||||
p3.setLayout(new GridLayout(2, 2));
|
||||
this.add(p3, BorderLayout.PAGE_END);
|
||||
JCheckBox cb = new JCheckBox("I agree");
|
||||
p3.add(cb);
|
||||
JRadioButton rb = new JRadioButton("Yes");
|
||||
p3.add(rb);
|
||||
JComboBox<String> cb1 = new JComboBox<String>(new String[]{"Red", "Green", "Blue"});
|
||||
p3.add(cb1);
|
||||
JComboBox<Integer> cb2 = new JComboBox<Integer>(new Integer[]{2, 7, -3, 24});
|
||||
p3.add(cb2);
|
||||
|
||||
this.setVisible(true); //if comment out, the window would not be visible
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel{
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
g.drawRect(20,20,60,60);
|
||||
g.drawRect(10,40,60,60);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel{
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
g.drawRect(30,10,60,60);
|
||||
g.drawRect(10,30,60,60);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel{
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
g.drawRect(30,10,60,60);
|
||||
g.drawRect(10,20,60,60);
|
||||
g.drawLine(30, 10, 10, 20);
|
||||
g.drawLine(90, 70, 70, 80);
|
||||
g.drawLine(90, 10, 70, 20);
|
||||
g.drawLine(30, 70, 10, 80);
|
||||
|
||||
g.setColor(Color.BLUE);
|
||||
g.drawOval(120, 10, 60, 15);
|
||||
g.drawOval(120, 70, 60, 15);
|
||||
g.drawLine(120, 17, 120, 77);
|
||||
g.drawLine(180, 17, 180, 77);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title"); //if comment out, the title would be blank
|
||||
this.setSize(400, 300); //if comment out, the initiated size would be 0
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //if comment out, the program would still running after clicked close button
|
||||
this.setLocationRelativeTo(null); //if comment out, the frame would appear at (0, 0)
|
||||
|
||||
//JButton b1 = new JButton("b1");
|
||||
this.add(new JButton("b1"), BorderLayout.LINE_START);
|
||||
//JButton b2 = new JButton("b2");
|
||||
this.add(new JButton("b2"), BorderLayout.LINE_END);
|
||||
|
||||
/* Only one button appear as Java would detect same button and remove
|
||||
JButton b = new JButton("B1");
|
||||
this.add(b);
|
||||
this.add(b);
|
||||
*/
|
||||
|
||||
/*
|
||||
FlowLayout f1 = new FlowLayout(FlowLayout.LEFT, 20, 40);
|
||||
this.setLayout(f1);
|
||||
*/
|
||||
|
||||
/*
|
||||
GridLayout g1 = new GridLayout(5, 5);
|
||||
this.setLayout(g1);
|
||||
*/
|
||||
//the program presents in 4*2 layout
|
||||
//the program did not use the specified rows and columns, because the lack numbers of components
|
||||
|
||||
BorderLayout bl = new BorderLayout();
|
||||
this.setLayout(bl);
|
||||
|
||||
JLabel l = new JLabel("Enter your name: ");
|
||||
this.add(l, BorderLayout.LINE_START);
|
||||
JTextField tx = new JTextField("Type Text Here");
|
||||
this.add(tx, BorderLayout.CENTER);
|
||||
JCheckBox cb = new JCheckBox("I agree");
|
||||
this.add(cb, BorderLayout.LINE_END);
|
||||
JRadioButton rb = new JRadioButton("Yes");
|
||||
this.add(rb, BorderLayout.AFTER_LINE_ENDS);
|
||||
JComboBox<String> cb1 = new JComboBox<String>(new String[]{"Red", "Green", "Blue"});
|
||||
this.add(cb1, BorderLayout.CENTER);
|
||||
JComboBox<Integer> cb2 = new JComboBox<Integer>(new Integer[]{2, 7, -3, 24});
|
||||
this.add(cb2, BorderLayout.LINE_END);
|
||||
|
||||
//when stretching the window, the components would realign to one row if space permits
|
||||
|
||||
this.setVisible(true); //if comment out, the window would not be visible
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title"); //if comment out, the title would be blank
|
||||
this.setSize(400, 300); //if comment out, the initiated size would be 0
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //if comment out, the program would still running after clicked close button
|
||||
this.setLocationRelativeTo(null); //if comment out, the frame would appear at (0, 0)
|
||||
|
||||
this.add(new MyPanel());
|
||||
|
||||
this.setVisible(true); //if comment out, the window would not be visible
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel{
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
g.drawRect(10,10,10,10);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title"); //if comment out, the title would be blank
|
||||
this.setSize(400, 300); //if comment out, the initiated size would be 0
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //if comment out, the program would still running after clicked close button
|
||||
this.setLocationRelativeTo(null); //if comment out, the frame would appear at (0, 0)
|
||||
|
||||
this.setLayout(new GridLayout(3, 1));
|
||||
|
||||
JPanel p1 = new JPanel();
|
||||
p1.setLayout(new BorderLayout());
|
||||
this.add(p1);
|
||||
p1.setBackground(Color.BLUE);
|
||||
p1.add(new JButton("b1"), BorderLayout.LINE_START);
|
||||
p1.add(new JButton("b2"), BorderLayout.LINE_END);
|
||||
|
||||
JPanel p2 = new JPanel();
|
||||
p2.setLayout(new FlowLayout(FlowLayout.CENTER));
|
||||
this.add(p2);
|
||||
p2.setBackground(Color.GREEN);
|
||||
JLabel l = new JLabel("Enter your name: ");
|
||||
p2.add(l);
|
||||
JTextField tx = new JTextField("Type Text Here");
|
||||
p2.add(tx);
|
||||
|
||||
JPanel p3 = new JPanel();
|
||||
p3.setLayout(new GridLayout(2, 2));
|
||||
this.add(p3);
|
||||
JCheckBox cb = new JCheckBox("I agree");
|
||||
p3.add(cb);
|
||||
JRadioButton rb = new JRadioButton("Yes");
|
||||
p3.add(rb);
|
||||
JComboBox<String> cb1 = new JComboBox<String>(new String[]{"Red", "Green", "Blue"});
|
||||
p3.add(cb1);
|
||||
JComboBox<Integer> cb2 = new JComboBox<Integer>(new Integer[]{2, 7, -3, 24});
|
||||
p3.add(cb2);
|
||||
|
||||
this.setVisible(true); //if comment out, the window would not be visible
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel{
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.BLUE);
|
||||
//g.drawString("hello",20, 80);
|
||||
g.drawString("hello",
|
||||
(int)Math.round(Math.random() * this.getWidth()),
|
||||
(int)Math.round(Math.random() * this.getHeight()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel{
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
g.drawRect(30,10,60,60);
|
||||
g.drawRect(10,20,60,60);
|
||||
g.drawLine(30, 10, 10, 20);
|
||||
g.drawLine(90, 70, 70, 80);
|
||||
g.drawLine(90, 10, 70, 20);
|
||||
g.drawLine(30, 70, 10, 80);
|
||||
|
||||
g.setColor(Color.BLUE);
|
||||
g.drawOval(120, 10, 60, 15);
|
||||
g.drawOval(120, 70, 60, 15);
|
||||
g.drawLine(120, 20, 120, 80);
|
||||
g.drawLine(120, 80, 120, 80);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel{
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
g.drawRect(30,20,60,60);
|
||||
g.drawRect(10,30,60,60);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel{
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
g.drawRect(30,10,60,60);
|
||||
g.drawRect(10,20,60,60);
|
||||
g.drawLine(30, 10, 10, 20);
|
||||
g.drawLine(90, 70, 70, 80);
|
||||
g.drawLine(90, 10, 70, 20);
|
||||
g.drawLine(30, 70, 10, 80);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel{
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
g.drawRect(30,10,60,60);
|
||||
g.drawRect(10,20,60,60);
|
||||
g.drawLine(30, 10, 10, 20);
|
||||
g.drawLine(90, 70, 70, 80);
|
||||
//g.drawLine(90, 10, 70, 10);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel{
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
g.drawRect(30,10,60,60);
|
||||
g.drawRect(10,20,60,60);
|
||||
g.drawLine(30, 10, 10, 20);
|
||||
g.drawLine(90, 70, 70, 80);
|
||||
g.drawLine(90, 10, 70, 20);
|
||||
g.drawLine(30, 70, 10, 80);
|
||||
|
||||
g.setColor(Color.BLUE);
|
||||
g.drawOval(120, 10, 60, 15);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title"); //if comment out, the title would be blank
|
||||
this.setSize(400, 300); //if comment out, the initiated size would be 0
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //if comment out, the program would still running after clicked close button
|
||||
this.setLocationRelativeTo(null); //if comment out, the frame would appear at (0, 0)
|
||||
|
||||
//JButton b1 = new JButton("b1");
|
||||
this.add(new JButton("b1"), BorderLayout.LINE_START);
|
||||
//JButton b2 = new JButton("b2");
|
||||
this.add(new JButton("b2"), BorderLayout.LINE_END);
|
||||
|
||||
/* Only one button appear as Java would detect same button and remove
|
||||
JButton b = new JButton("B1");
|
||||
this.add(b);
|
||||
this.add(b);
|
||||
*/
|
||||
|
||||
/*
|
||||
FlowLayout f1 = new FlowLayout(FlowLayout.LEFT, 20, 40);
|
||||
this.setLayout(f1);
|
||||
*/
|
||||
|
||||
/*
|
||||
GridLayout g1 = new GridLayout(5, 5);
|
||||
this.setLayout(g1);
|
||||
*/
|
||||
//the program presents in 4*2 layout
|
||||
//the program did not use the specified rows and columns, because the lack numbers of components
|
||||
|
||||
BorderLayout bl = new BorderLayout();
|
||||
this.setLayout(bl);
|
||||
|
||||
JLabel l = new JLabel("Enter your name: ");
|
||||
this.add(l, BorderLayout.AFTER_LINE_ENDS);
|
||||
JTextField tx = new JTextField("Type Text Here");
|
||||
this.add(tx, BorderLayout.CENTER);
|
||||
JCheckBox cb = new JCheckBox("I agree");
|
||||
this.add(cb, BorderLayout.LINE_END);
|
||||
JRadioButton rb = new JRadioButton("Yes");
|
||||
this.add(rb, BorderLayout.AFTER_LINE_ENDS);
|
||||
JComboBox<String> cb1 = new JComboBox<String>(new String[]{"Red", "Green", "Blue"});
|
||||
this.add(cb1, BorderLayout.CENTER);
|
||||
JComboBox<Integer> cb2 = new JComboBox<Integer>(new Integer[]{2, 7, -3, 24});
|
||||
this.add(cb2, BorderLayout.LINE_END);
|
||||
|
||||
//when stretching the window, the components would realign to one row if space permits
|
||||
|
||||
this.setVisible(true); //if comment out, the window would not be visible
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title"); //if comment out, the title would be blank
|
||||
this.setSize(400, 300); //if comment out, the initiated size would be 0
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //if comment out, the program would still running after clicked close button
|
||||
this.setLocationRelativeTo(null); //if comment out, the frame would appear at (0, 0)
|
||||
|
||||
JButton b1 = new JButton("b1");
|
||||
this.add(b1);
|
||||
JButton b2 = new JButton("b2");
|
||||
this.add(b2);
|
||||
|
||||
/* Only one button appear as Java would detect same button and remove
|
||||
JButton b = new JButton("B1");
|
||||
this.add(b);
|
||||
this.add(b);
|
||||
*/
|
||||
|
||||
FlowLayout f1 = new FlowLayout(FlowLayout.LEFT, 20, 40);
|
||||
this.setLayout(f1);
|
||||
|
||||
JLabel l = new JLabel("Enter your name: ");
|
||||
this.add(l);
|
||||
JTextField tx = new JTextField("Type Text Here");
|
||||
this.add(tx);
|
||||
JCheckBox cb = new JCheckBox("I agree");
|
||||
this.add(cb);
|
||||
JRadioButton rb = new JRadioButton("Yes");
|
||||
this.add(rb);
|
||||
JComboBox<String> cb1 = new JComboBox<String>(new String[]{"Red", "Green", "Blue"});
|
||||
this.add(cb1);
|
||||
JComboBox<Integer> cb2 = new JComboBox<Integer>(new Integer[]{2, 7, -3, 24});
|
||||
this.add(cb2);
|
||||
|
||||
//when stretching the window, the components would realign to one row if space permits
|
||||
|
||||
this.setVisible(true); //if comment out, the window would not be visible
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title");
|
||||
this.setSize(400, 300);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setLocationRelativeTo(null);
|
||||
|
||||
JButton b1 = new JButton("b1");
|
||||
this.add(b1);
|
||||
JButton b2 = new JButton("b2");
|
||||
this.add(b2);
|
||||
|
||||
/* Only one button appear as Java would detect same button and remove
|
||||
JButton b = new JButton("B1");
|
||||
this.add(b);
|
||||
this.add(b);
|
||||
*/
|
||||
|
||||
FlowLayout f1 = new FlowLayout(FlowLayout.LEFT, 20, 40);
|
||||
this.setLayout(f1);
|
||||
|
||||
this.setVisible(true); //if comment out, the window would not be visible
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel{
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
g.drawRect(30,10,60,60);
|
||||
g.drawRect(10,20,60,60);
|
||||
g.drawLine(30, 10, 10, 20);
|
||||
g.drawLine(90, 70, 70, 80);
|
||||
g.drawLine(90, 10, 70, 20);
|
||||
g.drawLine(30, 70, 10, 80);
|
||||
|
||||
g.setColor(Color.BLUE);
|
||||
g.drawOval(120, 10, 60, 20);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title"); //if comment out, the title would be blank
|
||||
this.setSize(400, 300); //if comment out, the initiated size would be 0
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //if comment out, the program would still running after clicked close button
|
||||
this.setLocationRelativeTo(null); //if comment out, the frame would appear at (0, 0)
|
||||
|
||||
JButton b1 = new JButton("b1");
|
||||
this.add(b1);
|
||||
JButton b2 = new JButton("b2");
|
||||
this.add(b2);
|
||||
|
||||
/* Only one button appear as Java would detect same button and remove
|
||||
JButton b = new JButton("B1");
|
||||
this.add(b);
|
||||
this.add(b);
|
||||
*/
|
||||
|
||||
/*
|
||||
FlowLayout f1 = new FlowLayout(FlowLayout.LEFT, 20, 40);
|
||||
this.setLayout(f1);
|
||||
*/
|
||||
|
||||
/*
|
||||
GridLayout g1 = new GridLayout(5, 5);
|
||||
this.setLayout(g1);
|
||||
*/
|
||||
//the program presents in 4*2 layout
|
||||
//the program did not use the specified rows and columns, because the lack numbers of components
|
||||
|
||||
BorderLayout b1 = new BorderLayout();
|
||||
this.setLayout(b1);
|
||||
|
||||
JLabel l = new JLabel("Enter your name: ");
|
||||
this.add(l);
|
||||
JTextField tx = new JTextField("Type Text Here");
|
||||
this.add(tx);
|
||||
JCheckBox cb = new JCheckBox("I agree");
|
||||
this.add(cb);
|
||||
JRadioButton rb = new JRadioButton("Yes");
|
||||
this.add(rb);
|
||||
JComboBox<String> cb1 = new JComboBox<String>(new String[]{"Red", "Green", "Blue"});
|
||||
this.add(cb1);
|
||||
JComboBox<Integer> cb2 = new JComboBox<Integer>(new Integer[]{2, 7, -3, 24});
|
||||
this.add(cb2);
|
||||
|
||||
//when stretching the window, the components would realign to one row if space permits
|
||||
|
||||
this.setVisible(true); //if comment out, the window would not be visible
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel{
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
g.drawRect(30,10,60,60);
|
||||
g.drawRect(10,20,60,60);
|
||||
g.drawLine(30, 10, 10, 20);
|
||||
g.drawLine(90, 70, 70, 90);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title"); //if comment out, the title would be blank
|
||||
this.setSize(400, 300); //if comment out, the initiated size would be 0
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //if comment out, the program would still running after clicked close button
|
||||
this.setLocationRelativeTo(null); //if comment out, the frame would appear at (0, 0)
|
||||
|
||||
JButton b1 = new JButton("b1");
|
||||
this.add(b1);
|
||||
JButton b2 = new JButton("b2");
|
||||
this.add(b2);
|
||||
|
||||
/* Only one button appear as Java would detect same button and remove
|
||||
JButton b = new JButton("B1");
|
||||
this.add(b);
|
||||
this.add(b);
|
||||
*/
|
||||
|
||||
/*
|
||||
FlowLayout f1 = new FlowLayout(FlowLayout.LEFT, 20, 40);
|
||||
this.setLayout(f1);
|
||||
*/
|
||||
|
||||
GridLayout g1 = new GridLayout();
|
||||
this.setLayout(g1);
|
||||
|
||||
JLabel l = new JLabel("Enter your name: ");
|
||||
this.add(l);
|
||||
JTextField tx = new JTextField("Type Text Here");
|
||||
this.add(tx);
|
||||
JCheckBox cb = new JCheckBox("I agree");
|
||||
this.add(cb);
|
||||
JRadioButton rb = new JRadioButton("Yes");
|
||||
this.add(rb);
|
||||
JComboBox<String> cb1 = new JComboBox<String>(new String[]{"Red", "Green", "Blue"});
|
||||
this.add(cb1);
|
||||
JComboBox<Integer> cb2 = new JComboBox<Integer>(new Integer[]{2, 7, -3, 24});
|
||||
this.add(cb2);
|
||||
|
||||
//when stretching the window, the components would realign to one row if space permits
|
||||
|
||||
this.setVisible(true); //if comment out, the window would not be visible
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel{
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.BLUE);
|
||||
g.drawString("hello",20, 80);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel{
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
g.drawRect(30,10,60,60);
|
||||
g.drawRect(10,20,60,60);
|
||||
g.drawLine(30, 10, 10, 20);
|
||||
g.drawLine(90, 70, 70, 80);
|
||||
g.drawLine(90, 10, 70, 20);
|
||||
g.drawLine(30, 70, 10, 80);
|
||||
|
||||
g.setColor(Color.BLUE);
|
||||
g.drawOval(120, 10, 60, 15);
|
||||
g.drawOval(120, 70, 60, 15);
|
||||
g.drawLine(120, 17, 120, 77);
|
||||
g.drawLine(180, 27, 180, 77);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel{
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
g.drawRect(10,10,100,100);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel{
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
g.drawRect(30,10,60,60);
|
||||
g.drawRect(10,20,60,60);
|
||||
g.drawLine(30, 10, 10, 20);
|
||||
g.drawLine(90, 70, 70, 80);
|
||||
g.drawLine(90, 10, 70, 20);
|
||||
g.drawLine(30, 70, 10, 80);
|
||||
|
||||
g.setColor(Color.BLUE);
|
||||
g.drawOval(120, 10, 60, 15);
|
||||
g.drawOval(120, 70, 60, 15);
|
||||
g.drawLine(120, 20, 120, 80);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title"); //if comment out, the title would be blank
|
||||
this.setSize(400, 300); //if comment out, the initiated size would be 0
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //if comment out, the program would still running after clicked close button
|
||||
this.setLocationRelativeTo(null); //if comment out, the frame would appear at (0, 0)
|
||||
|
||||
JPanel p1 = new JPanel();
|
||||
BorderLayout bl = new BorderLayout();
|
||||
p1.setLayout(bl);
|
||||
this.add(p1);
|
||||
p1.add(new JButton("b1"), BorderLayout.LINE_START);
|
||||
p1.add(new JButton("b2"), BorderLayout.LINE_END);
|
||||
|
||||
JPanel p2 = new JPanel();
|
||||
FlowLayout f1 = new FlowLayout(FlowLayout.CENTER);
|
||||
p2.setLayout(f1);
|
||||
this.add(p2);
|
||||
JLabel l = new JLabel("Enter your name: ");
|
||||
p2.add(l);
|
||||
JTextField tx = new JTextField("Type Text Here");
|
||||
p2.add(tx);
|
||||
|
||||
JPanel p3 = new JPanel();
|
||||
GridLayout g1 = new GridLayout(2, 2);
|
||||
p3.setLayout(g1);
|
||||
this.add(p3);
|
||||
JCheckBox cb = new JCheckBox("I agree");
|
||||
p3.add(cb);
|
||||
JRadioButton rb = new JRadioButton("Yes");
|
||||
p3.add(rb);
|
||||
JComboBox<String> cb1 = new JComboBox<String>(new String[]{"Red", "Green", "Blue"});
|
||||
p3.add(cb1);
|
||||
JComboBox<Integer> cb2 = new JComboBox<Integer>(new Integer[]{2, 7, -3, 24});
|
||||
p3.add(cb2);
|
||||
|
||||
this.setVisible(true); //if comment out, the window would not be visible
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title");
|
||||
this.setSize(400, 300);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setLocationRelativeTo(null);
|
||||
|
||||
//JButton b1 = new JButton("b1");
|
||||
this.add(new JButton("b1"), BorderLayout.LINE_START);
|
||||
//JButton b2 = new JButton("b2");
|
||||
this.add(new JButton("b2"), BorderLayout.LINE_END);
|
||||
|
||||
/*
|
||||
GridLayout g1 = new GridLayout(5, 5);
|
||||
this.setLayout(g1);
|
||||
*/
|
||||
//the program presents in 4*2 layout
|
||||
//the program did not use the specified rows and columns, because the lack numbers of components
|
||||
//the layout did not changed as the components are already parallel-aligned
|
||||
//if set number of rows = 0, it would auto ask new lines w.r.t. number of columns
|
||||
|
||||
BorderLayout bl = new BorderLayout();
|
||||
this.setLayout(bl);
|
||||
|
||||
JLabel l = new JLabel("Enter your name: ");
|
||||
this.add(l, BorderLayout.LINE_START);
|
||||
JTextField tx = new JTextField("Type Text Here");
|
||||
this.add(tx, BorderLayout.CENTER);
|
||||
JCheckBox cb = new JCheckBox("I agree");
|
||||
this.add(cb, BorderLayout.LINE_END);
|
||||
JRadioButton rb = new JRadioButton("Yes");
|
||||
this.add(rb, BorderLayout.AFTER_LINE_ENDS);
|
||||
JComboBox<String> cb1 = new JComboBox<String>(new String[]{"Red", "Green", "Blue"});
|
||||
this.add(cb1, BorderLayout.CENTER);
|
||||
JComboBox<Integer> cb2 = new JComboBox<Integer>(new Integer[]{2, 7, -3, 24});
|
||||
this.add(cb2, BorderLayout.LINE_END);
|
||||
//when add more than one component to one of the five areas of the frame, overlap would occurs
|
||||
//when one area does not contain any components, this area would missing
|
||||
|
||||
this.setVisible(true);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title"); //if comment out, the title would be blank
|
||||
this.setSize(400, 300); //if comment out, the initiated size would be 0
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //if comment out, the program would still running after clicked close button
|
||||
this.setLocationRelativeTo(null); //if comment out, the frame would appear at (0, 0)
|
||||
|
||||
JButton b1 = new JButton("b1");
|
||||
this.add(b1);
|
||||
JButton b2 = new JButton("b2");
|
||||
this.add(b2);
|
||||
|
||||
/* Only one button appear as Java would detect same button and remove
|
||||
JButton b = new JButton("B1");
|
||||
this.add(b);
|
||||
this.add(b);
|
||||
*/
|
||||
|
||||
/*
|
||||
FlowLayout f1 = new FlowLayout(FlowLayout.LEFT, 20, 40);
|
||||
this.setLayout(f1);
|
||||
*/
|
||||
|
||||
GridLayout g1 = new GridLayout(5, 5);
|
||||
this.setLayout(g1);
|
||||
|
||||
JLabel l = new JLabel("Enter your name: ");
|
||||
this.add(l);
|
||||
JTextField tx = new JTextField("Type Text Here");
|
||||
this.add(tx);
|
||||
JCheckBox cb = new JCheckBox("I agree");
|
||||
this.add(cb);
|
||||
JRadioButton rb = new JRadioButton("Yes");
|
||||
this.add(rb);
|
||||
JComboBox<String> cb1 = new JComboBox<String>(new String[]{"Red", "Green", "Blue"});
|
||||
this.add(cb1);
|
||||
JComboBox<Integer> cb2 = new JComboBox<Integer>(new Integer[]{2, 7, -3, 24});
|
||||
this.add(cb2);
|
||||
|
||||
//when stretching the window, the components would realign to one row if space permits
|
||||
|
||||
this.setVisible(true); //if comment out, the window would not be visible
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel{
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
g.drawRect(20,20,60,60);
|
||||
g.drawRect(10,30,60,60);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title"); //if comment out, the title would be blank
|
||||
this.setSize(400, 300); //if comment out, the initiated size would be 0
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //if comment out, the program would still running after clicked close button
|
||||
this.setLocationRelativeTo(null); //if comment out, the frame would appear at (0, 0)
|
||||
|
||||
//JButton b1 = new JButton("b1");
|
||||
//JButton b2 = new JButton("b2");
|
||||
this.add(new JButton("b1"), BorderLayout.LINE_START);
|
||||
this.add(new JButton("b2"), BorderLayout.LINE_END);
|
||||
|
||||
/* Only one button appear as Java would detect same button and remove
|
||||
JButton b = new JButton("B1");
|
||||
this.add(b);
|
||||
this.add(b);
|
||||
*/
|
||||
|
||||
/*
|
||||
FlowLayout f1 = new FlowLayout(FlowLayout.LEFT, 20, 40);
|
||||
this.setLayout(f1);
|
||||
*/
|
||||
|
||||
/*
|
||||
GridLayout g1 = new GridLayout(5, 5);
|
||||
this.setLayout(g1);
|
||||
*/
|
||||
//the program presents in 4*2 layout
|
||||
//the program did not use the specified rows and columns, because the lack numbers of components
|
||||
|
||||
BorderLayout bl = new BorderLayout();
|
||||
this.setLayout(bl);
|
||||
|
||||
JLabel l = new JLabel("Enter your name: ");
|
||||
this.add(l, BorderLayout.LINE_START);
|
||||
JTextField tx = new JTextField("Type Text Here");
|
||||
this.add(tx, BorderLayout.CENTER);
|
||||
JCheckBox cb = new JCheckBox("I agree");
|
||||
this.add(cb, BorderLayout.LINE_END);
|
||||
JRadioButton rb = new JRadioButton("Yes");
|
||||
this.add(rb, BorderLayout.AFTER_LINE_ENDS);
|
||||
JComboBox<String> cb1 = new JComboBox<String>(new String[]{"Red", "Green", "Blue"});
|
||||
this.add(cb1, BorderLayout.CENTER);
|
||||
JComboBox<Integer> cb2 = new JComboBox<Integer>(new Integer[]{2, 7, -3, 24});
|
||||
this.add(cb2, BorderLayout.LINE_END);
|
||||
//when add more than one component to one of the five areas of the frame, overlap would occurs
|
||||
//when one area does not contain any components, this area would missing
|
||||
|
||||
//when stretching the window, the components would realign to one row if space permits
|
||||
|
||||
this.setVisible(true); //if comment out, the window would not be visible
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title"); //if comment out, the title would be blank
|
||||
this.setSize(400, 300); //if comment out, the initiated size would be 0
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //if comment out, the program would still running after clicked close button
|
||||
this.setLocationRelativeTo(null); //if comment out, the frame would appear at (0, 0)
|
||||
|
||||
//JButton b1 = new JButton("b1");
|
||||
this.add(new JButton("b1"), BorderLayout.LINE_START);
|
||||
//JButton b2 = new JButton("b2");
|
||||
this.add(new JButton("b2"), BorderLayout.LINE_END);
|
||||
|
||||
/* Only one button appear as Java would detect same button and remove
|
||||
JButton b = new JButton("B1");
|
||||
this.add(b);
|
||||
this.add(b);
|
||||
*/
|
||||
|
||||
/*
|
||||
FlowLayout f1 = new FlowLayout(FlowLayout.LEFT, 20, 40);
|
||||
this.setLayout(f1);
|
||||
*/
|
||||
|
||||
/*
|
||||
GridLayout g1 = new GridLayout(5, 5);
|
||||
this.setLayout(g1);
|
||||
*/
|
||||
//the program presents in 4*2 layout
|
||||
//the program did not use the specified rows and columns, because the lack numbers of components
|
||||
|
||||
BorderLayout bl = new BorderLayout();
|
||||
this.setLayout(bl);
|
||||
|
||||
JLabel l = new JLabel("Enter your name: ");
|
||||
this.add(l, BorderLayout.LINE_START);
|
||||
JTextField tx = new JTextField("Type Text Here");
|
||||
this.add(tx, BorderLayout.CENTER);
|
||||
JCheckBox cb = new JCheckBox("I agree");
|
||||
this.add(cb, BorderLayout.LINE_END);
|
||||
JRadioButton rb = new JRadioButton("Yes");
|
||||
this.add(rb, BorderLayout.AFTER_LINE_ENDS);
|
||||
JComboBox<String> cb1 = new JComboBox<String>(new String[]{"Red", "Green", "Blue"});
|
||||
this.add(cb1, BorderLayout.CENTER);
|
||||
JComboBox<Integer> cb2 = new JComboBox<Integer>(new Integer[]{2, 7, -3, 24});
|
||||
this.add(cb2, BorderLayout.LINE_END);
|
||||
|
||||
//when stretching the window, the components would realign to one row if space permits
|
||||
|
||||
this.setVisible(true); //if comment out, the window would not be visible
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title"); //if comment out, the title would be blank
|
||||
this.setSize(400, 300); //if comment out, the initiated size would be 0
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //if comment out, the program would still running after clicked close button
|
||||
this.setLocationRelativeTo(null); //if comment out, the frame would appear at (0, 0)
|
||||
|
||||
this.setLayout(new GridLayout(3, 1));
|
||||
|
||||
JPanel p1 = new JPanel();
|
||||
p1.setLayout(new BorderLayout());
|
||||
this.add(p1);
|
||||
p1.setBackground(Color.BLUE);
|
||||
p1.add(new JButton("b1"), BorderLayout.LINE_START);
|
||||
p1.add(new JButton("b2"), BorderLayout.LINE_END);
|
||||
|
||||
JPanel p2 = new JPanel();
|
||||
p2.setLayout(new FlowLayout(FlowLayout.CENTER));
|
||||
this.add(p2);
|
||||
p2.setBackground(Color.GREEN);
|
||||
JLabel l = new JLabel("Enter your name: ");
|
||||
p2.add(l);
|
||||
JTextField tx = new JTextField("Type Text Here");
|
||||
p2.add(tx);
|
||||
|
||||
JPanel p3 = new JPanel();
|
||||
p3.setLayout(new GridLayout(2, 2));
|
||||
this.add(p3);
|
||||
JCheckBox cb = new JCheckBox("I agree");
|
||||
p3.add(cb);
|
||||
JRadioButton rb = new JRadioButton("Yes");
|
||||
p3.add(rb);
|
||||
JComboBox<String> cb1 = new JComboBox<String>(new String[]{"Red", "Green", "Blue"});
|
||||
p3.add(cb1);
|
||||
JComboBox<Integer> cb2 = new JComboBox<Integer>(new Integer[]{2, 7, -3, 24});
|
||||
p3.add(cb2);
|
||||
|
||||
this.setVisible(true); //if comment out, the window would not be visible
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title"); //if comment out, the title would be blank
|
||||
this.setSize(400, 300); //if comment out, the initiated size would be 0
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //if comment out, the program would still running after clicked close button
|
||||
this.setLocationRelativeTo(null); //if comment out, the frame would appear at (0, 0)
|
||||
|
||||
JPanel p1 = new JPanel();
|
||||
p1.setLayout(new BorderLayout());
|
||||
this.add(p1);
|
||||
p1.add(new JButton("b1"), BorderLayout.LINE_START);
|
||||
p1.add(new JButton("b2"), BorderLayout.LINE_END);
|
||||
|
||||
JPanel p2 = new JPanel();
|
||||
p2.setLayout(new FlowLayout(FlowLayout.CENTER));
|
||||
this.add(p2);
|
||||
JLabel l = new JLabel("Enter your name: ");
|
||||
p2.add(l);
|
||||
JTextField tx = new JTextField("Type Text Here");
|
||||
p2.add(tx);
|
||||
|
||||
JPanel p3 = new JPanel();
|
||||
p3.setLayout(new GridLayout(2, 2));
|
||||
this.add(p3);
|
||||
JCheckBox cb = new JCheckBox("I agree");
|
||||
p3.add(cb);
|
||||
JRadioButton rb = new JRadioButton("Yes");
|
||||
p3.add(rb);
|
||||
JComboBox<String> cb1 = new JComboBox<String>(new String[]{"Red", "Green", "Blue"});
|
||||
p3.add(cb1);
|
||||
JComboBox<Integer> cb2 = new JComboBox<Integer>(new Integer[]{2, 7, -3, 24});
|
||||
p3.add(cb2);
|
||||
|
||||
this.setVisible(true); //if comment out, the window would not be visible
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel{
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
g.drawString("hello",20, 80);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel{
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
g.drawRect(50,50,60,60);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel{
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
//g.setColor(Color.BLUE);
|
||||
//g.drawString("hello",20, 80);
|
||||
g.drawString("hello",
|
||||
(int)Math.round(Math.random() * this.getWidth()),
|
||||
(int)Math.round(Math.random() * this.getHeight()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title"); //if comment out, the title would be blank
|
||||
this.setSize(400, 300); //if comment out, the initiated size would be 0
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //if comment out, the program would still running after clicked close button
|
||||
this.setLocationRelativeTo(null); //if comment out, the frame would appear at (0, 0)
|
||||
|
||||
this.setLayout(new FlowLayout(FlowLayout.CENTER));
|
||||
|
||||
JPanel p1 = new JPanel();
|
||||
p1.setLayout(new BorderLayout());
|
||||
this.add(p1);
|
||||
p1.setBackground(Color.BLUE);
|
||||
p1.add(new JButton("b1"), BorderLayout.LINE_START);
|
||||
p1.add(new JButton("b2"), BorderLayout.LINE_END);
|
||||
|
||||
JPanel p2 = new JPanel();
|
||||
p2.setLayout(new FlowLayout(FlowLayout.CENTER));
|
||||
this.add(p2);
|
||||
p2.setBackground(Color.GREEN);
|
||||
JLabel l = new JLabel("Enter your name: ");
|
||||
p2.add(l);
|
||||
JTextField tx = new JTextField("Type Text Here");
|
||||
p2.add(tx);
|
||||
|
||||
JPanel p3 = new JPanel();
|
||||
p3.setLayout(new GridLayout(2, 2));
|
||||
this.add(p3);
|
||||
JCheckBox cb = new JCheckBox("I agree");
|
||||
p3.add(cb);
|
||||
JRadioButton rb = new JRadioButton("Yes");
|
||||
p3.add(rb);
|
||||
JComboBox<String> cb1 = new JComboBox<String>(new String[]{"Red", "Green", "Blue"});
|
||||
p3.add(cb1);
|
||||
JComboBox<Integer> cb2 = new JComboBox<Integer>(new Integer[]{2, 7, -3, 24});
|
||||
p3.add(cb2);
|
||||
|
||||
this.setVisible(true); //if comment out, the window would not be visible
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel{
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
g.drawRect(10,10,60,60);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
|
||||
public class Start {
|
||||
|
||||
public static void main(String[] args) {
|
||||
javax.swing.SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
new MyFrame();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title");
|
||||
this.setSize(400, 300);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setLocationRelativeTo(null);
|
||||
|
||||
//JButton b1 = new JButton("b1");
|
||||
this.add(new JButton("b1"), BorderLayout.LINE_START);
|
||||
//JButton b2 = new JButton("b2");
|
||||
this.add(new JButton("b2"), BorderLayout.LINE_END);
|
||||
|
||||
/*
|
||||
GridLayout g1 = new GridLayout(5, 5);
|
||||
this.setLayout(g1);
|
||||
*/
|
||||
//the program presents in 4*2 layout
|
||||
//the program did not use the specified rows and columns, because the lack numbers of components
|
||||
//the layout did not changed as the components are already parallel-aligned
|
||||
//if set number of rows = 0, it would aligned in one row
|
||||
|
||||
BorderLayout bl = new BorderLayout();
|
||||
this.setLayout(bl);
|
||||
|
||||
JLabel l = new JLabel("Enter your name: ");
|
||||
this.add(l, BorderLayout.LINE_START);
|
||||
JTextField tx = new JTextField("Type Text Here");
|
||||
this.add(tx, BorderLayout.CENTER);
|
||||
JCheckBox cb = new JCheckBox("I agree");
|
||||
this.add(cb, BorderLayout.LINE_END);
|
||||
JRadioButton rb = new JRadioButton("Yes");
|
||||
this.add(rb, BorderLayout.AFTER_LINE_ENDS);
|
||||
JComboBox<String> cb1 = new JComboBox<String>(new String[]{"Red", "Green", "Blue"});
|
||||
this.add(cb1, BorderLayout.CENTER);
|
||||
JComboBox<Integer> cb2 = new JComboBox<Integer>(new Integer[]{2, 7, -3, 24});
|
||||
this.add(cb2, BorderLayout.LINE_END);
|
||||
//when add more than one component to one of the five areas of the frame, overlap would occurs
|
||||
//when one area does not contain any components, this area would missing
|
||||
|
||||
this.setVisible(true);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title"); //if comment out, the title would be blank
|
||||
this.setSize(400, 300); //if comment out, the initiated size would be 0
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //if comment out, the program would still running after clicked close button
|
||||
this.setLocationRelativeTo(null); //if comment out, the frame would appear at (0, 0)
|
||||
|
||||
//JButton b1 = new JButton("b1");
|
||||
this.add(new JButton("b1"), BorderLayout.LINE_START);
|
||||
//JButton b2 = new JButton("b2");
|
||||
this.add(new JButton("b2"), BorderLayout.LINE_END);
|
||||
|
||||
/* Only one button appear as Java would detect same button and remove
|
||||
JButton b = new JButton("B1");
|
||||
this.add(b);
|
||||
this.add(b);
|
||||
*/
|
||||
|
||||
/*
|
||||
FlowLayout f1 = new FlowLayout(FlowLayout.LEFT, 20, 40);
|
||||
this.setLayout(f1);
|
||||
*/
|
||||
|
||||
/*
|
||||
GridLayout g1 = new GridLayout(5, 5);
|
||||
this.setLayout(g1);
|
||||
*/
|
||||
//the program presents in 4*2 layout
|
||||
//the program did not use the specified rows and columns, because the lack numbers of components
|
||||
|
||||
BorderLayout bl = new BorderLayout();
|
||||
this.setLayout(bl);
|
||||
|
||||
JLabel l = new JLabel("Enter your name: ");
|
||||
this.add(l, BorderLayout.PAGE_START);
|
||||
JTextField tx = new JTextField("Type Text Here");
|
||||
this.add(tx, BorderLayout.CENTER);
|
||||
JCheckBox cb = new JCheckBox("I agree");
|
||||
this.add(cb, BorderLayout.LINE_END);
|
||||
JRadioButton rb = new JRadioButton("Yes");
|
||||
this.add(rb, BorderLayout.AFTER_LINE_ENDS);
|
||||
JComboBox<String> cb1 = new JComboBox<String>(new String[]{"Red", "Green", "Blue"});
|
||||
this.add(cb1, BorderLayout.CENTER);
|
||||
JComboBox<Integer> cb2 = new JComboBox<Integer>(new Integer[]{2, 7, -3, 24});
|
||||
this.add(cb2, BorderLayout.LINE_END);
|
||||
|
||||
//when stretching the window, the components would realign to one row if space permits
|
||||
|
||||
this.setVisible(true); //if comment out, the window would not be visible
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title"); //if comment out, the title would be blank
|
||||
this.setSize(400, 300); //if comment out, the initiated size would be 0
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //if comment out, the program would still running after clicked close button
|
||||
this.setLocationRelativeTo(null); //if comment out, the frame would appear at (0, 0)
|
||||
|
||||
this.setLayout(new BorderLayout());
|
||||
|
||||
JPanel p1 = new JPanel();
|
||||
p1.setLayout(new BorderLayout());
|
||||
this.add(p1, BorderLayout.PAGE_START);
|
||||
p1.setBackground(Color.BLUE);
|
||||
p1.add(new JButton("b1"), BorderLayout.LINE_START);
|
||||
p1.add(new JButton("b2"), BorderLayout.LINE_END);
|
||||
|
||||
JPanel p2 = new JPanel();
|
||||
p2.setLayout(new FlowLayout(FlowLayout.CENTER));
|
||||
this.add(p2, BorderLayout.CENTER);
|
||||
p2.setBackground(Color.GREEN);
|
||||
JLabel l = new JLabel("Enter your name: ");
|
||||
p2.add(l);
|
||||
JTextField tx = new JTextField("Type Text Here");
|
||||
p2.add(tx);
|
||||
|
||||
JPanel p3 = new JPanel();
|
||||
p3.setLayout(new GridLayout(2, 2));
|
||||
this.add(p3, BorderLayout.PAGE_END);
|
||||
JCheckBox cb = new JCheckBox("I agree");
|
||||
p3.add(cb);
|
||||
JRadioButton rb = new JRadioButton("Yes");
|
||||
p3.add(rb);
|
||||
JComboBox<String> cb1 = new JComboBox<String>(new String[]{"Red", "Green", "Blue"});
|
||||
p3.add(cb1);
|
||||
JComboBox<Integer> cb2 = new JComboBox<Integer>(new Integer[]{2, 7, -3, 24});
|
||||
p3.add(cb2);
|
||||
|
||||
this.setVisible(true); //if comment out, the window would not be visible
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel{
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
g.drawRect(30,10,60,60);
|
||||
g.drawRect(10,20,60,60);
|
||||
g.drawLine(30, 10, 10, 20);
|
||||
g.drawLine(90, 70, 70, 80);
|
||||
g.drawLine(90, 10, 70, 20);
|
||||
g.drawLine(30, 70, 10, 80);
|
||||
|
||||
g.setColor(Color.BLUE);
|
||||
g.drawOval(120, 10, 60, 15);
|
||||
g.drawOval(120, 70, 60, 15);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MyFrame extends JFrame{
|
||||
//constructor
|
||||
public MyFrame() {
|
||||
this.setTitle("MyFrame Title"); //if comment out, the title would be blank
|
||||
this.setSize(400, 300); //if comment out, the initiated size would be 0
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //if comment out, the program would still running after clicked close button
|
||||
this.setLocationRelativeTo(null); //if comment out, the frame would appear at (0, 0)
|
||||
|
||||
JButton b1 = new JButton("b1");
|
||||
this.add(b1);
|
||||
JButton b2 = new JButton("b2");
|
||||
this.add(b2);
|
||||
|
||||
/*
|
||||
* Only one button appear as Java would detect same button and remove
|
||||
JButton b = new JButton("B1");
|
||||
this.add(b);
|
||||
this.add(b);
|
||||
*/
|
||||
|
||||
/*
|
||||
FlowLayout f1 = new FlowLayout(FlowLayout.LEFT, 20, 40);
|
||||
this.setLayout(f1);
|
||||
*/
|
||||
|
||||
GridLayout g1 = new GridLayout(5, 5);
|
||||
this.setLayout(g1);
|
||||
|
||||
JLabel l = new JLabel("Enter your name: ");
|
||||
this.add(l);
|
||||
JTextField tx = new JTextField("Type Text Here");
|
||||
this.add(tx);
|
||||
JCheckBox cb = new JCheckBox("I agree");
|
||||
this.add(cb);
|
||||
JRadioButton rb = new JRadioButton("Yes");
|
||||
this.add(rb);
|
||||
JComboBox<String> cb1 = new JComboBox<String>(new String[]{"Red", "Green", "Blue"});
|
||||
this.add(cb1);
|
||||
JComboBox<Integer> cb2 = new JComboBox<Integer>(new Integer[]{2, 7, -3, 24});
|
||||
this.add(cb2);
|
||||
|
||||
//when stretching the window, the components would realign to one row if space permits
|
||||
|
||||
this.setVisible(true); //if comment out, the window would not be visible
|
||||
}
|
||||
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user