import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Main extends JFrame {
int g;
String s = "Love Java";
JLabel l = new JLabel(s);
Main() {
setTitle("+,-키로 폰트 크기 조절");
Container c = getContentPane();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
c.setLayout(new FlowLayout());
c.add(l);
l.setLayout(null);
c.addKeyListener(new MyKeyListener());
c.setFocusable(true);
c.requestFocus();
l.setOpaque(true);
l.setFont(new Font("Arial", Font.PLAIN, 50));
setSize(500, 200);
setVisible(true);
}
class MyKeyListener extends KeyAdapter {
public void keyPressed(KeyEvent e) {
int KeyCode = e.getKeyCode();
Font f = l.getFont();
int size = f.getSize();
if (e.getKeyChar() == '+') {
System.out.println("++");
l.setFont(new Font("Arial", Font.PLAIN, size + 5));
} else if (e.getKeyCode() == KeyEvent.VK_MINUS) {
l.setFont(new Font("Arial", Font.PLAIN, size - 5));
}
}
@Override
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub
}
@Override
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
}
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Main extends JFrame {
String text="Love Java";
JLabel l = new JLabel("Love Java");
int i=0;
Main() {
setTitle("LEFT 키로 문자열 이동");
Container c = getContentPane();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
c.setLayout(new FlowLayout());
c.add(l);
l.setLayout(null);
c.addKeyListener(new MyKeyListener());
c.setFocusable(true);
c.requestFocus();
String text = new String();
l.setOpaque(true);
l.setFont(new Font("Arial", Font.PLAIN, 25));
setSize(500, 200);
setVisible(true);
}
class MyKeyListener extends KeyAdapter {
public void keyPressed(KeyEvent e) {
int KeyCode = e.getKeyCode();
if (e.getKeyCode() == KeyEvent.VK_LEFT) {
i=i+1;
l.setText(text.substring(i)+text.substring(0,i));
if(i==9)
{
i=0;
}
}
}
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Main extends JFrame{
int a=1000000;
int d=0;
int g;
String b=Integer.toString(a);
JLabel l=new JLabel(" 0");
JLabel l1=new JLabel(" 0");
JLabel l2=new JLabel(" 0");
JLabel l3=new JLabel("시작합니다.");
JLabel l4=new JLabel("기본자금:"+b+"(원)");
JButton t=new JButton("돌리기");
JTextField f=new JTextField(25);
Main(){
setTitle("도 박");
Container c = getContentPane();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
c.setLayout(null);
l.setLocation(50, 100);
l1.setLocation(200, 100);
l2.setLocation(350, 100);
l3.setLocation(200,235);
l4.setLocation(270,10);
f.setLocation(10, 10);
t.setLocation(190, 200);
l.setSize(80, 45);
l1.setSize(80, 45);
l2.setSize(80, 45);
l3.setSize(80,45);
l4.setSize(160,60);
f.setSize(160,20);
t.setSize(80,40);
c.add(l);
c.add(l1);
c.add(l2);
c.add(l3);
c.add(l4);
c.add(f);
c.add(t);
c.setBackground(Color.DARK_GRAY);
l.setBackground(Color.magenta);
l1.setBackground(Color.magenta);
l2.setBackground(Color.magenta);
l.setForeground(Color.yellow);
l1.setForeground(Color.yellow);
l2.setForeground(Color.yellow);
f.setBackground(Color.white);
t.setBackground(Color.CYAN);
t.setForeground(Color.ORANGE);
l.setOpaque(true);
l1.setOpaque(true);
l2.setOpaque(true);
l3.setOpaque(true);
l4.setOpaque(true);
f.setOpaque(true);
t.setOpaque(true);
l3.setBackground(Color.DARK_GRAY);
l4.setBackground(Color.DARK_GRAY);
l4.setForeground(Color.LIGHT_GRAY);
l4.setForeground(Color.white);
l.setFont(new Font("Arial", Font.ITALIC, 40));
l1.setFont(new Font("Arial", Font.ITALIC, 40));
l2.setFont(new Font("Arial", Font.ITALIC, 40));
t.addMouseListener(new MyMouseListener());
setSize(500,350);
setVisible(true);
}
class MyMouseListener extends MouseAdapter{
public void mouseClicked(MouseEvent e) {
d=a;
if(f.getText().equals("")) return ;// 아무것도 입력되지 않았다면
if(g==1)
{
System.exit(0);
}
if(Integer.valueOf(f.getText())>a)
{
return;
}
int x=(int)(Math.random()*9);
int y=(int)(Math.random()*9);
int z=(int)(Math.random()*9);
l.setText(Integer.toString(x));
l1.setText(Integer.toString(y));
l2.setText(Integer.toString(z));
if(x==y&&y==z)
{
d=Integer.valueOf(f.getText())*14;
b=Integer.toString(a+d);
a=a+d;
l4.setText("기본자금:"+b+"(원)");
l3.setText("ㄲㅂ");
}
else
{
if(a-Integer.valueOf(f.getText())<0) {
l4.setText("파산");
l3.setText("잘가");
g=1;
}
else
{
a=a-Integer.valueOf(f.getText());
b=Integer.toString(a);
l4.setText("기본자금:"+b+"(원)");
l3.setText("ㅋ");
}
}
f.setText(null);
}
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Main extends JFrame{
Main(){
super("JComponent의 공통 메소드 예제");
Container c=getContentPane();
c.setLayout(new FlowLayout());
JButton b1=new JButton("Magenta/Yellow Button");
JButton b2=new JButton(" Disabled Button ");
JButton b3=new JButton("getX(), getY()");
b1.setBackground(Color.yellow);
b1.setForeground(Color.magenta);
b1.setFont(new Font("Arial",Font.ITALIC,20));
b2.setEnabled(false);
b3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
JButton b=(JButton)e.getSource();
Main frame=(Main)b.getTopLevelAncestor();
frame.setTitle(b.getX()+","+b.getY());
}
});
c.add(b1);
c.add(b2);
c.add(b3);
setSize(260,200);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}
*/
import javax.swing.*;
import java.awt.*;
public class Main extends JFrame{
Main()
{
setTitle("레이블 예제");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c=getContentPane();
c.setLayout(new FlowLayout());
JLabel TextLabel=new JLabel("사랑합니다");
ImageIcon beauty=new ImageIcon("heart.png");
JLabel imageLabel=new JLabel(beauty);
ImageIcon normalIcon = new ImageIcon("images/normalIcon.jpg");
JLabel Label=new JLabel("보고싶으면 전화하세요",
normalIcon,SwingConstants.CENTER);
c.add(TextLabel);
c.add(imageLabel);
c.add(Label);
setSize(400,600);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}