package main;
import javax.swing.*;
import java.awt.*;
public class BorderLayoutEx extends JFrame {
BorderLayoutEx() {
setTitle("BorderLayout Sample");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
add(new JButton("Console"), BorderLayout.SOUTH);
add(new JButton("Test.java"), BorderLayout.CENTER);
add(new JButton("Package Explorer"), BorderLayout.WEST);
setSize(600, 400);
setVisible(true);
}
public static void main(String[] args) {
new BorderLayoutEx();
}
}
package main;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
public class MySwing01 extends JFrame{
MySwing01(){
setTitle("Multiple Layout Example"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel contentP=new JPanel();
contentP.setLayout(new BorderLayout());
JPanel upperP = new JPanel();
upperP.setLayout(new GridLayout(1, 2));
JPanel leftP=new JPanel();
leftP.setLayout(new GridLayout(4,1));
leftP.setBackground(Color.YELLOW);
leftP.add(new JLabel("Type ID", SwingConstants.CENTER));
leftP.add(new JTextField(""));
leftP.add(new JLabel("Type Password", SwingConstants.CENTER));
leftP.add(new JTextField(""));
upperP.add(leftP);
JPanel rightP=new JPanel();
rightP.setLayout(new GridLayout(3,1));
rightP.setBackground(Color.GREEN);
rightP.add(new JLabel("Plaese check!!", SwingConstants.CENTER));
rightP.add(new JLabel("C# JCheckBox", SwingConstants.CENTER));
rightP.add(new JLabel("C++ JCheckBox", SwingConstants.CENTER));
upperP.add(rightP);
contentP.add(upperP);
JPanel lowerP=new JPanel();
JButton okB=new JButton("OK");
okB.setPreferredSize(new Dimension(100,30));
lowerP.add(okB);
contentP.add(lowerP, BorderLayout.SOUTH);
add(contentP);
setSize(300, 200); setVisible(true);
}
public static void main(String[] args) {
new MySwing01();
}
}
package _1117_C;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class main extends JFrame {
JLabel label;
main() {
setTitle("버튼 눌러 텍스트 보여주기");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel grid = new JPanel();
grid.setLayout(new GridLayout(2, 1));
JPanel topGrid = new JPanel();
topGrid.setLayout(new GridLayout(1, 3));
JButton button1 = new JButton("Hannam");
JButton button2 = new JButton("University");
JButton button3 = new JButton("Student");
topGrid.add(button1);
topGrid.add(button2);
topGrid.add(button3);
grid.add(topGrid);
label = new JLabel("Press Button", SwingConstants.CENTER);
grid.add(label);
add(grid);
setSize(300, 150);
setVisible(true);
MyActionListener listener = new MyActionListener();
button1.addActionListener(listener);
button2.addActionListener(listener);
button3.addActionListener(listener);
}
private class MyActionListener implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
label.setText(((JButton)e.getSource()).getText());
}
}
public static void main(String[] args) {
new main();
}
}
package _1117_D;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
public class _1117C extends JFrame {
JLabel label;
JPanel grid;
_1117C() {
setTitle("버튼 눌러 텍스트 보여주기");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
grid = new JPanel();
grid.setLayout(new GridLayout(2, 1));
JPanel topGrid = new JPanel();
topGrid.setLayout(new GridLayout(1, 3));
JButton button1 = new JButton("Hannam");
JButton button2 = new JButton("University");
JButton button3 = new JButton("Student");
topGrid.add(button1);
topGrid.add(button2);
topGrid.add(button3);
grid.add(topGrid);
label = new JLabel("Press Button", SwingConstants.CENTER);
grid.add(label);
MyActionListener listener = new MyActionListener();
button1.addActionListener(listener);
button2.addActionListener(listener);
button3.addActionListener(listener);
}
public JPanel getPanel()
{
return grid;
}
private class MyActionListener implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
label.setText(((JButton)e.getSource()).getText());
}
}
}
package _1117_D;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class main extends JFrame {
private JPanel contentPane;
private JPanel panelUp;
private JPanel panelDown;
private JButton buttonLeft;
private JButton buttonCenter;
private JButton buttonRight;
private JPanel panelLeft;
private JPanel panelCenter;
private JPanel panelRight;
private JLabel labelNewLabel_1;
private JButton buttonNewButton;
private JButton buttonNewButton_1;
private JButton buttonNewButton_2;
private final static String PANEL_LEFT = "버튼3개";
private final static String PANEL_CENTER = "이전연습문제";
private final static String PANEL_RIGHT = "글자";
public static void main(String[] args) {
main frame = new main();
frame.setVisible(true);
}
public main() {
setTitle("CardLayout 사용하기");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 600, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
panelUp = new JPanel();
contentPane.add(panelUp, BorderLayout.NORTH);
buttonLeft = new JButton(PANEL_LEFT);
buttonLeft.addActionListener(new MyActionListener());
panelUp.add(buttonLeft);
buttonCenter = new JButton(PANEL_CENTER);
buttonCenter.addActionListener(new MyActionListener());
panelUp.add(buttonCenter);
buttonRight = new JButton(PANEL_RIGHT);
buttonRight.addActionListener(new MyActionListener());
panelUp.add(buttonRight);
panelDown = new JPanel();
contentPane.add(panelDown, BorderLayout.CENTER);
panelDown.setLayout(new CardLayout());
panelLeft = new JPanel();
buttonNewButton = new JButton("button1");
panelLeft.add(buttonNewButton);
buttonNewButton_1 = new JButton("button2");
panelLeft.add(buttonNewButton_1);
buttonNewButton_2 = new JButton("button3");
panelLeft.add(buttonNewButton_2);
panelDown.add(panelLeft, PANEL_LEFT);
panelCenter = new JPanel();
_1117C center = new _1117C();
panelCenter.add(center.getPanel());
panelDown.add(panelCenter, PANEL_CENTER);
panelRight = new JPanel();
labelNewLabel_1 = new JLabel("오른쪽 입니다");
panelRight.add(labelNewLabel_1);
panelDown.add(panelRight, PANEL_RIGHT);
}
private class MyActionListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
JButton button = (JButton) e.getSource();
CardLayout cl = (CardLayout) (panelDown.getLayout());
cl.show(panelDown, button.getText());
}
}
}
'기타 > univ. projects' 카테고리의 다른 글
[자바] 멀티미디어자바프로젝트II 최종 프로젝트 (0) | 2022.12.21 |
---|---|
[자바] 멀티미디어자바프로젝트II ch.10 연습문제 (0) | 2022.11.24 |
[유니티] 게임엔진응용실습 Unit6 프로젝트 - Zombie Run (FPS 게임) (0) | 2022.11.19 |
[유니티] 게임엔진응용실습 Unit5 프로젝트 - Tower Defense (Windows & Android) (0) | 2022.11.05 |
[자바] 멀티미디어자바프로젝트II ch.08 연습문제 (0) | 2022.11.01 |