/*
import java.awt.event.*;
import javax.swing.*;
public class Main extends JFrame{
public Main() {
setSize(1000,1000);
setLayout(new BorderLayout());
JPanel pd = new JPanel();
pd.setLayout(new FlowLayout());
JButton b2 = new JButton(new ImageIcon("free-icon-right-arrow-109617.png"));
JButton b1 = new JButton(new ImageIcon("free-icon-left-arrow-8167741.png"));
pd.add(b1); pd.add(b2);
add(pd,BorderLayout.SOUTH);
JPanel pc = new JPanel();
pc.setLayout(new FlowLayout());
JLabel l1 = new JLabel(new ImageIcon("free-icon-avatar-1752681.png"));
JLabel l2 = new JLabel(new ImageIcon("free-icon-psyduck-189000.png"));
JLabel l3= new JLabel(new ImageIcon("free-icon-eevee-188995.png"));
JLabel l4 = new JLabel(new ImageIcon("free-icon-pikachu-188939.png"));
pc.add(l1);
add(pc,BorderLayout.CENTER);
setVisible(true);
}
class
public static void main(String[] args) {
new Main();
}
}
aaaaaaaaa
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Main extends JFrame{
public Main() {
setLayout(new FlowLayout());
Container c = getContentPane();
c.setLayout(new FlowLayout());
JButton b1 = new JButton("Magenta/yellow button");
JButton b2 = new JButton(" disabled butten ");
JButton b3 = new JButton("getx(),gety()");
JButton b4 = new JButton(new ImageIcon("hearts.png"));
JLabel la1 = new JLabel(new ImageIcon("hearts.png"));
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();
String str =b.getX() + "," + b.getY();
b3.setText(str);
}
});
c.add(b1);
c.add(b2);
c.add(b3);
c.add(b4);
c.add(la1);
setSize(700,700);
setVisible(true);
}
public static void main(String[] args) {
new Main();
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Main extends JFrame {
int num=1;
JButton b = new JButton(new ImageIcon("one.png"));
ImageIcon[] img = {new ImageIcon("one.png"),new ImageIcon("two.png"),new ImageIcon("three.png"),new ImageIcon("four.png")};
public Main() {
setSize(1000, 1000);
setLayout(new BorderLayout());
JPanel p = new JPanel();
p.setLayout(new FlowLayout());
JButton b1 = new JButton(new ImageIcon("left-arrow.png"));
JButton b2 = new JButton(new ImageIcon("right-arrow.png"));
b1.addActionListener(new MA1()); b2.addActionListener(new MA2());
p.add(b1);
p.add(b2);
add(p, BorderLayout.SOUTH);
JPanel p1 = new JPanel();
p1.setLayout(new FlowLayout());
p1.add(b);
add(p1, BorderLayout.CENTER);
setVisible(true);
}
class MA1 implements ActionListener{
public void actionPerformed(ActionEvent e) {
if(num==1) num=4;
else num--;
b.setIcon(img[num-1]);
repaint();
}
}
class MA2 implements ActionListener{
public void actionPerformed(ActionEvent e) {
if(num==4) num=1;
else num++;
b.setIcon(img[num-1]);
repaint();
}
}
public static void main(String[] args) {
new Main();
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Main extends JFrame {
int money = 0;
String name = "ma";
JLabel la1 = new JLabel("name");
JLabel la3 = new JLabel("0원");
JCheckBox cb1 = new JCheckBox("햄버거(5천원)");
JCheckBox cb2 = new JCheckBox("피자(3십만원)");
JCheckBox cb3 = new JCheckBox("치킨(1원)");
JRadioButton rb1 = new JRadioButton("진우");
JRadioButton rb2 = new JRadioButton("지우");
JRadioButton rb3 = new JRadioButton("지운");
public Main() {
setSize(500, 300);
Container c = getContentPane();
c.setLayout(new BorderLayout());
JPanel p1 = new JPanel();
JPanel p2 = new JPanel();
c.add(p1, BorderLayout.NORTH);
c.add(p2, BorderLayout.CENTER);
p1.add(cb1);
p1.add(cb2);
p1.add(cb3);
cb1.addItemListener(new MI1());
cb2.addItemListener(new MI1());
cb3.addItemListener(new MI1());
rb1.addItemListener(new MT2());
rb2.addItemListener(new MT2());
rb3.addItemListener(new MT2());
ButtonGroup gr = new ButtonGroup();
gr.add(rb1);
gr.add(rb2);
gr.add(rb3);
p1.add(rb1);
p1.add(rb2);
p1.add(rb3);
JLabel la = new JLabel("이름 : ");
JLabel la2 = new JLabel("가격 : ");
p2.add(la);
p2.add(la1);
p2.add(la2);
p2.add(la3);
setVisible(true);
}
class MI1 implements ItemListener {
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
if (e.getItem() == cb1) {
money += 5000;
}
else if (e.getItem() == cb2) {
money += 300000;
}
else if (e.getItem() == cb3) {
money += 1;
}
}
else {
if (e.getItem() == cb1) {
money -= 4999;
}
else if (e.getItem() == cb2) {
money -= 300000;
} else {
money -= 1;
}
}
la3.setText(Integer.toString(money) + "원");
}
}
class MT2 implements ItemListener {
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
if (e.getItem() == rb1) {
name = rb1.getText();
}
else if (e.getItem() == rb2) {
name = rb2.getText();
}
else if (e.getItem() == rb3) {
name = rb3.getText();
}
la1.setText(name);
}
}
}
public static void main(String[] args) {
new Main();
}
}
*/
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.*;
public class Main extends JFrame{
JSlider sl1 = new JSlider(JSlider.VERTICAL, 0, 255, 100);
JSlider sl2 = new JSlider(JSlider.VERTICAL,0,255,100);
JSlider sl3 = new JSlider(JSlider.VERTICAL,0,255,100);
JSlider sl4 = new JSlider(JSlider.VERTICAL,0,200,100);
JLabel l1 = new JLabel(Integer.toString(sl1.getValue()));
JLabel l2 = new JLabel(Integer.toString(sl2.getValue()));
JLabel l3 = new JLabel(Integer.toString(sl3.getValue()));
JLabel la = new JLabel("hello");
Container c = getContentPane();
public Main(){
setTitle("슬라이더 만들기");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
c.setLayout(new FlowLayout());
la.setForeground(new Color(100,100,100));
la.setSize(100,100);
sl1.setPaintLabels(true);
sl2.setPaintLabels(true);
sl3.setPaintLabels(true);
sl4.setPaintLabels(true);
sl1.setPaintTicks(true);
sl2.setPaintTicks(true);
sl3.setPaintTicks(true);
sl4.setPaintTicks(true);
sl1.setForeground(Color.red);
sl2.setForeground(Color.green);
sl3.setForeground(Color.blue);
sl1.setPaintTrack(true);
sl2.setPaintTrack(true);
sl3.setPaintTrack(true);
sl4.setPaintTrack(true);
sl1.setMajorTickSpacing(50);
sl2.setMajorTickSpacing(50);
sl3.setMajorTickSpacing(50);
sl4.setMajorTickSpacing(50);
sl1.setMinorTickSpacing(10);
sl2.setMinorTickSpacing(10);
sl3.setMinorTickSpacing(10);
sl4.setMinorTickSpacing(10);
sl1.addChangeListener(new MyChangeListener());
sl2.addChangeListener(new MyChangeListener());
sl3.addChangeListener(new MyChangeListener());
sl4.addChangeListener(new MyChangeListener());
c.add(sl1);
c.add(l1);
c.add(sl2);
c.add(l2);
c.add(sl3);
c.add(l3);
c.add(sl4);
c.add(la);
la.setSize(100,100);
setSize(1000,1000);
setVisible(true);
}
class MyChangeListener implements ChangeListener{
public void stateChanged(ChangeEvent e) {
Color color1 = new Color(sl1.getValue(),sl2.getValue(),sl3.getValue());
la.setForeground(color1);
int size = la.getFont().getSize();
la.setFont(new Font("Arial",Font.PLAIN , sl4.getValue()));
l1.setText(Integer.toString(sl1.getValue()));
l2.setText(Integer.toString(sl2.getValue()));
l3.setText(Integer.toString(sl3.getValue()));
}
}
public static void main(String[] args) {
new Main();
}
}