import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Main extends JFrame{
public Main() {
setTitle("아씨 어지러워");
setDefaultCloseOperation(EXIT_ON_CLOSE);
Container c = getContentPane();
setSize(200,400);
setVisible(true);
c.add(new MyPanel(), BorderLayout.SOUTH);
}
class MyPanel extends Panel{
private JButton b = new JButton("ㅎㅏㄱ ㅂ ㅓ ㄴ");
private JTextField t = new JTextField(10);
public MyPanel() {
add(b);
add(t);
t.addKeyListener(new KeyListener() {
public void keyTyped(KeyEvent e) {
char key = e.getKeyChar();
if('0'<=key&&key<='9') {
}
else {
e.consume();
JOptionPane.showMessageDialog(null, "씁어허", "씁", JOptionPane.ERROR_MESSAGE);
}
}
public void keyPressed(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
}
});
}}public static void main(String[] args) {
new Main();
}}
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Main extends JFrame{
private JLabel l = new JLabel("Hello");
public Main() {
setTitle("ddjkasopfl;,");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
l.setHorizontalAlignment(SwingConstants.CENTER);
l.setFont(new Font("Revive",Font.ITALIC,30));
c.add(l,BorderLayout.CENTER);
createMenu();
setSize(250,250);
setVisible(true);
}
private void createMenu() {
JMenuBar mb = new JMenuBar();
JMenuItem colorMenuItem = new JMenuItem("color");
JMenu fileMenu = new JMenu("text");
colorMenuItem.addActionListener(new MenuActionListener());
fileMenu.add(colorMenuItem);
mb.add(fileMenu);
this.setJMenuBar(mb);
}
class MenuActionListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
if(cmd.equals("Color"));
Color selectedColor = JColorChooser.showDialog(null, "color", Color.YELLOW);
if(selectedColor != null) {
l.setForeground(selectedColor);
}
}
}
public static void main(String[] args) {
new Main();
}
}
import javax.swing.*;
import java.awt.*;
public class Main extends JFrame{
public Main(){
setTitle("ljksdc");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
JTabbedPane pane = createTabbedPane();
c.add(pane,BorderLayout.CENTER);
setSize(250,250);
setVisible(true);
}
private JTabbedPane createTabbedPane() {
JTabbedPane pane = new JTabbedPane();
pane.addTab("tab1",new JLabel(new ImageIcon("ipad-reverse.png")));
pane.addTab("tab2",new JLabel(new ImageIcon("lion.png")));
pane.addTab("tab3",new JLabel(new ImageIcon("plum.png")));
return pane;
}
class MyPanel extends JPanel{
public MyPanel() {
this.setBackground(Color.yellow);
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.red);
g.fillRect(10, 10, 50, 50);
g.setColor(Color.BLUE);
g.fillOval(10, 70, 50, 50);
g.setColor(Color.black);
g.drawString("bhiwqrjnfnkxz", 30, 50);
}
}
public static void main(String[] args) {
new Main();
}
}
탭팬 + 가위바위보게임, 숫자순서대로누르기게임, 슬라이더, 버튼, 키리스너 , 회원가입페이지, 색바꾸기
계산기
hello색깔 바꾸기,더하기,학번 등록하기,맞추기,hello 출력
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Main extends JFrame{
int n=0;
Container c = getContentPane();
JLabel l[] = new JLabel[100];
JLabel l1 = new JLabel(Integer.toString(n));
public Main(){
setSize(300, 300);
setVisible(true);
c.setLayout(null);
c.add(l1);
l1.setVisible(true);
l1.setLocation(100,100);
l1.setSize(30,30);
for(int i=0;i<10;i++) {
l[i] = new JLabel(Integer.toString(i)); //정수를 문자열로
int x =(int)(Math.random()*200)+50; //랜덤
int y =(int)(Math.random()*200)+50; //랜덤
l[i].setLocation(x, y);
l[i].setSize(30, 30);
c.add(l[i]);
l[i].addMouseListener(new MyMouseLisener());
}
}
public class MyMouseLisener extends MouseAdapter{
public void mousePressed(MouseEvent e) {
JLabel la = (JLabel)e.getSource();
if(Integer.valueOf(la.getText())==n) {
n++;
l1.setText(Integer.toString(n));
la.setVisible(false);
}
else {
l1.setText("풉");
}
}
}
public static void main(String[] args) {
new Main();
}
}