import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Main extends JFrame {
JLabel l = new JLabel("c");
int f = 0;
Main() {
setTitle("ㄴ");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
l.addMouseListener(new MyMouseListener());
c.setLayout(null);
l.setLocation(100, 100);
l.setSize(20, 20);
c.add(l);
l.setOpaque(true);
setSize(500, 500);
setVisible(true);
}
class MyMouseListener extends MouseAdapter {
public void actionPerformed(ActionEvent e) {
}
public void mouseClicked(MouseEvent e) {
int x = (int) (Math.random() * 400) + 50;
int y = (int) (Math.random() * 400) + 50;
l.setLocation(x, y);
l.setOpaque(true);
}
}
public static void main(String[] args) {
new Main();
}
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Main extends JFrame{
JLabel l=new JLabel("Love Java");
Main()
{
setTitle("마우스 휠을 굴려 폰트 크기 조...");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c=getContentPane();
c.setLayout(null);
l.setLocation(100, 100);
l.setSize(200, 50);
c.add(l);
l.addMouseWheelListener(new MouseWheelListener(){
public void mouseWheelMoved(MouseWheelEvent e) {
int size = l.getFont().getSize();
int n=e.getWheelRotation();
if(n<0)
{
if(5>=l.getFont().getSize()-5)
{
return;
}
l.setFont(new Font("Arial",Font.PLAIN,size-5));
}
else
{
l.setFont(new Font("Arial",Font.PLAIN,size+5));
}
}
});
l.setOpaque(true);
setSize(500,500);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Main extends JFrame{
private JLabel [] keyMessage;
Main(){
setTitle("ketListener 예제");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c=getContentPane();
c.setLayout(new FlowLayout());
c.addKeyListener(new MyKeyListener());
keyMessage=new JLabel[3];
keyMessage[0]=new JLabel(" getKeyCode() ");
keyMessage[1]=new JLabel(" getKeyChar() ");
keyMessage[2]=new JLabel(" getKeytext() ");
for(int i=0;i<keyMessage.length;i++)
{
c.add(keyMessage[i]);
keyMessage[i].setOpaque(true);
keyMessage[i].setBackground(Color.yellow);
}
setSize(300,150);
setVisible(true);
c.setFocusable(true);
c.requestFocus();
}
class MyKeyListener extends KeyAdapter{
public void keyPressed(KeyEvent e) {
int keyCode=e.getKeyCode();
char keyChar = e.getKeyChar();
keyMessage[0].setText(Integer.toString(keyCode));
keyMessage[1].setText(Character.toString(keyChar));
keyMessage[2].setText(KeyEvent.getKeyText(keyCode));
System.out.println("KeyPressed");
}
public void keyReleased(KeyEvent e) {
System.out.println("KeyReleased");
}
public void keyTyped(KeyEvent e) {
System.out.println("KeyTyped");
}
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Main extends JFrame{
Container c=getContentPane();
JLabel key=new JLabel();
Main()
{
setTitle("Key Code 예제 : F1키:초록색,...");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
c.setLayout(new FlowLayout());
c.addKeyListener(new MyKeyListener());
key=new JLabel("getKeyCode()");
c.add(key);
setSize(700,500);
setVisible(true);
c.setFocusable(true);
c.requestFocus();
}
class MyKeyListener extends KeyAdapter{
public void keyPressed(KeyEvent e) {
int keyCode=e.getKeyCode();
key.setText(KeyEvent.getKeyText(keyCode));
if(KeyEvent.getKeyText(keyCode).equals("5"))
{
c.setBackground(Color.green);
}
else if(KeyEvent.getKeyText(keyCode).equals("F1"))
{
c.setBackground(Color.yellow);
}
else
{
c.setBackground(Color.white);
}
}
public void keyTyped(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
}
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Main extends JFrame{Container c=getContentPane();
JLabel l=new JLabel("HELLO");
Main()
{
setTitle("상,하,좌,우 키를 이용하여 텍스...");
c.setLayout(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
l.setLocation(50, 50);
l.setSize(60,20);
l.setOpaque(true);
c.add(l);
c.addKeyListener(new MyKeyListener());
c.setFocusable(true);
c.requestFocus();
setSize(300,300);
setVisible(true);
}
class MyKeyListener extends KeyAdapter{
public void keyPressed(KeyEvent e) {
int keyCode=e.getKeyCode();
l.setForeground(new Color((int)(Math.random()*255),(int)(Math.random()*255),(int)(Math.random()*255)));
if(e.getKeyCode()==KeyEvent.VK_LEFT&&l.getX()>0)
{
l.setLocation(l.getX()-10, l.getY());
}
else if(e.getKeyCode()==KeyEvent.VK_UP&&l.getY()>0)
{
l.setLocation(l.getX(),l.getY()-10);
}
else if(e.getKeyCode()==KeyEvent.VK_RIGHT&&l.getX()<240)
{
l.setLocation(l.getX()+10, l.getY());
}
else if(e.getKeyCode()==KeyEvent.VK_DOWN&&l.getY()<240)
{
l.setLocation(l.getX(), l.getY()+10);
}
}
}
public static void main(String[] args) {
//O ㅇ O o O o O o O o O
new Main();
}
}
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Main extends JFrame
{
String s = "Love Java";
JLabel l=new JLabel(s);
Main()
{
setTitle("Left 키로 문자열 교체");
Container c=getContentPane();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
c.setLayout(new FlowLayout());
c.add(l);
c.addKeyListener(new MyKeyListener());
c.setFocusable(true);
c.requestFocus();
l.setOpaque(true);
setSize(500,200);
setVisible(true);
}
class MyKeyListener extends KeyAdapter{
public void keyPressed(KeyEvent e) {
int KeyCode=e.getKeyCode();
if(e.getKeyCode()==KeyEvent.VK_LEFT)
{
StringBuffer st = new StringBuffer(s);
l.setText(st.reverse().toString());
s=l.getText();
}
}
}
public static void main(String[] args) {
new Main();
}
}