top of page

게시판 게시물

15088sk1@naver.com
2023년 2월 19일
In 소스 코드 제출
/* hello색깔 바꾸기,더하기,학번 등록하기,맞추기,hello 출력 */ import javax.swing.*; import java.awt.*; import java.awt.event.MouseAdapter; public class Main extends JFrame{ JPanel p = new JPanel(); JPanel p1 = new JPanel(); JPanel p2 = new JPanel(); JPanel p3 = new JPanel(); JPanel p4 = new JPanel(); JPanel p5 = new JPanel(); JPanel p6 = new JPanel(); JPanel p7 = new JPanel(); 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); p.setLayout(new FlowLayout()); JSlider slider = new JSlider(JSlider.HORIZONTAL,0,200,100); slider.setPaintLabels(true); slider.setPaintTicks(true); slider.setPaintTrack(true); slider.setMajorTickSpacing(50); slider.setMinorTickSpacing(10); p.add(slider); p1.setLayout(new FlowLayout()); JButton b = new JButton("눌러눌러 돈이 나가나가나가나가나가나가나가나가나가나가"); JLabel l = new JLabel("자산 :10e+10000000"); p1.add(b); p1.add(l); JLabel l2 = new JLabel(); JLabel l3[] = new JLabel[100]; int n=0; JLabel l1 = new JLabel(Integer.toString(n)); setSize(300, 300); setVisible(true); c.setLayout(null); c.add(l1); l2.setVisible(true); l2.setLocation(100,100); l2.setSize(30,30); for(int i=0;i<10;i++) { l3[i] = new JLabel(Integer.toString(i)); int x =(int)(Math.random()*200)+50; int y =(int)(Math.random()*200)+50; l3[i].setLocation(x, y); l3[i].setSize(30, 30); c.add(l3[i]); l3[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("풉"); } } } } private JTabbedPane createTabbedPane() { JTabbedPane pane = new JTabbedPane(); pane.addTab( "Slider",p); pane.addTab("color", p1); return pane; } public static void main(String[] args) { new Main(); } }
0
0
3
15088sk1@naver.com
2023년 2월 12일
In 소스 코드 제출
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(); } }
0
0
4
15088sk1@naver.com
2022년 12월 11일
In 소스 코드 제출
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[10]; 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(); } } */ import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Main extends JFrame { JLabel imgLabel = new JLabel(); public Main() { setTitle("menu만들기 예제"); createmenu(); getContentPane().add(imgLabel,BorderLayout.CENTER); setSize(250,220); setVisible(true); } private void createmenu() { JMenuBar mb = new JMenuBar(); JMenuItem [] menu } public static void main(String[] args) { new Main(); } }
0
0
4
15088sk1@naver.com
2022년 11월 19일
In 소스 코드 제출
/* import java.awt.*; import java.awt.event.*; import java.util.Random; import javax.swing.*; public class Main extends JFrame { ImageIcon i1 = new ImageIcon("fist.png"); ImageIcon i2 = new ImageIcon("hand.png"); ImageIcon i3 = new ImageIcon("scissor.png"); JButton b1 = new JButton(i1); JButton b2 = new JButton(i2); JButton b3 = new JButton(i3); JPanel p1 = new JPanel(); JPanel p2 = new JPanel(); JLabel[] l = new JLabel[5]; Container c = getContentPane(); public Main() { setVisible(true); setSize(850, 500); setLayout(new BorderLayout()); p1.setLayout(new FlowLayout()); p2.setLayout(new FlowLayout()); p1.add(b1); p1.add(b2); p1.add(b3); b1.addActionListener(new MyActionListener()); b2.addActionListener(new MyActionListener()); b3.addActionListener(new MyActionListener()); for (int i = 0; i < 5; i++) { l[i] = new JLabel(); p2.add(l[i]); } l[1].setText("me"); l[3].setText("com"); l[4].setForeground(Color.red); c.add(p1, BorderLayout.NORTH); p1.setBackground(Color.LIGHT_GRAY); c.add(p2, BorderLayout.CENTER); p2.setBackground(Color.YELLOW); } class MyActionListener implements ActionListener { public void actionPerformed(ActionEvent e) { JButton b = (JButton)e.getSource(); int r = (int)(Math.random()*10); if(r==0) { l[2].setIcon(i1); } else if(r==1) { l[2].setIcon(i2); } else { l[2].setIcon(i3); } if(b==b1) { //me 주먹 l[0].setIcon(i1); if(r==0) { // l[4].setText("same"); } else if(r==1) { l[4].setText("com"); } else { l[4].setText("me"); } } else if(b==b2) {//보 l[0].setIcon(i2); if(r==0) { l[4].setText("me"); } else if(r==1) { l[4].setText("same"); } else { l[4].setText("com"); } } else { l[0].setIcon(i3);//가위 if(r==2) { l[4].setText("same"); } else if(r==1) { l[4].setText("me"); } else { l[4].setText("com"); } } } } public static void main(String[] args) { new Main(); } } */ import java.awt.*; import java.awt.event.*; import java.util.Random; import javax.swing.*; public class Main extends JFrame{ Container c = getContentPane(); JLabel[] la = new JLabel[10]; public Main() { setSize(300,300); setVisible(true); setLayout(null); for(int i=0;i<10;i++) { la[i] = new JLabel(Integer.toString(i)); //Integer.valueOf("123") int x = (int)(Math.random()*200) + 50; int y = (int)(Math.random()*200) + 50; la[i].setSize(7, 7); la[i].setLocation(x, y); c.add(la[i]); } c.addMouseListener(new mo()); } class mo implements MouseListener{ public void mouseClicked(MouseEvent e) { } @Override public void mousePressed(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseReleased(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseEntered(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseExited(MouseEvent e) { // TODO Auto-generated method stub } } public static void main(String[] args) { new Main(); } }
0
0
3
15088sk1@naver.com
2022년 11월 13일
In 소스 코드 제출
/*import java.awt.event.*; import javax.swing.*; import java.awt.*; public class Main extends JFrame { JButton b1 = new JButton(); JCheckBox cb = new JCheckBox(" 비할 성하 버튼"); JCheckBox cb2 = new JCheckBox("감추기 버튼"); public Main() { Container c = getContentPane(); setSize(100, 400); setVisible(true); c.setLayout(new FlowLayout()); c.add(cb); c.add(cb2); c.add(b1); cb.addItemListener(new MyItemListener()); cb2.addItemListener(new MyItemListener()); } class MyItemListener implements ItemListener { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { if (e.getItem() == cb) { b1.setEnabled(false); } else { b1.setVisible(false); } } if (e.getStateChange() == ItemEvent.DESELECTED) { if (e.getItem() == cb) { b1.setEnabled(true); } else { b1.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 { JRadioButton rb1 = new JRadioButton("left왼"); JRadioButton rb2 = new JRadioButton("right오"); JPanel p1 = new JPanel(); JPanel p2 = new JPanel(); JLabel l; ImageIcon b = new ImageIcon("meowth.png"); ImageIcon b1 = new ImageIcon("ball.png"); Container c = getContentPane(); public Main() { ButtonGroup g = new ButtonGroup(); JRadioButton rb1 = new JRadioButton("left왼"); JRadioButton rb2 = new JRadioButton("right오"); c.setLayout(new BorderLayout()); p2.add(rb1); p2.add(rb2); c.add(p2, BorderLayout.NORTH); l = new JLabel(b); g.add(rb2); g.add(rb1); rb1.addItemListener(new MyitemListener()); rb2.addItemListener(new MyitemListener()); p1.setLayout(new FlowLayout()); p1.add(l); c.add(p1, BorderLayout.CENTER); setSize(1000, 1000); setVisible(true); } class MyitemListener implements ItemListener { public void itemStateChanged(ItemEvent e) { if (rb1.isSelected()) { l.setIcon(b); } else if (rb2.isSelected()) { l.setIcon(b1); } } } public static void main(String[] args) { new Main(); } }
0
0
2
15088sk1@naver.com
2022년 11월 06일
In 소스 코드 제출
/* 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(); } }
0
0
2
15088sk1@naver.com
2022년 10월 30일
In 소스 코드 제출
/*import java.awt.*; 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(); } }
0
0
5
15088sk1@naver.com
2022년 10월 23일
In 소스 코드 제출
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Main extends JFrame { JLabel l = new JLabel("zz"); public Main() { Container c = getContentPane(); setSize(1000, 1000); setVisible(true); c.addKeyListener(new MyKeyListener()); c.setLayout(new FlowLayout()); c.add(l); c.setFocusable(true); c.requestFocus(); } class MyKeyListener extends KeyAdapter { public void keyPressed(KeyEvent e) { int size = l.getFont().getSize(); if(e.getKeyCode() == 107) { l.setFont( new Font("Arial", Font.PLAIN, size+5) ); } else if(e.getKeyCode() == 109) { if(size-5>5) l.setFont(new Font("Arial", Font.PLAIN, size-5)); } } } public static void main(String[] args) { new Main(); } } import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Main extends JFrame{ JLabel l = new JLabel("사라하 자바"); public Main() { setSize(700,700); setVisible(true); Container c = getContentPane(); l.addMouseWheelListener(new MyMouseWheelListener()); c.setLayout(new FlowLayout()); c.add(l); } class MyMouseWheelListener implements MouseWheelListener{ public void mouseWheelMoved(MouseWheelEvent e) { int n = e.getWheelRotation(); int size = l.getFont().getSize(); if(n < 0) { l.setFont( new Font("고딕", Font.PLAIN, size+5) ); } else { if(size-5>5) l.setFont(new Font("고딕", Font.CENTER_BASELINE, size-5)); } } } public static void main(String[] args) { new Main(); } } */ /* 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{ 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(); } }
0
0
3
15088sk1@naver.com
2022년 10월 16일
In 소스 코드 제출
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Main extends JFrame{ JLabel l = new JLabel("자바"); public Main() { setTitle("마우스를 올리기 내리................."); Container c = getContentPane(); c.setLayout(new FlowLayout()); l.addMouseListener(new MyMouseListener()); c.add(l); setSize(1000,1000); setVisible(true); } class MyMouseListener extends MouseAdapter { public void mouseEntered(MouseEvent e) { l.setText("나락"); } public void mouseExited(MouseEvent e) { l.setText("극락"); } } public static void main(String[] args) { new Main(); } } import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Main extends JFrame{ Container c = getContentPane(); public Main() { setSize(1000,1000); setVisible(true); c.setBackground(Color.gray); c.addMouseMotionListener(new MyMouseMotionListener() ); } class MyMouseMotionListener implements MouseMotionListener{ public void mouseDragged(MouseEvent e) { c.setBackground(Color.YELLOW); } @Override public void mouseMoved(MouseEvent e) { c.setBackground(Color.green); } } public static void main(String[] args) { new Main(); } } import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Main extends JFrame{ JLabel l = new JLabel("자바"); public Main() { Container c = getContentPane(); setSize(1000,1000); setVisible(true); c.addKeyListener(new MyKeyListener()); c.add(l); c.setLayout(new FlowLayout()); c.setFocusable(true); c.requestFocus(); } class MyKeyListener extends KeyAdapter{ public void keyPressed(KeyEvent e) { if(e.getKeyCode() == KeyEvent.VK_LEFT) { l.setText("wkqk"); } } public void keyReleased(KeyEvent e) { if(e.getKeyCode() == KeyEvent.VK_LEFT) { l.setText("자바"); } } } public static void main(String[] args) { new Main(); } } import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Main extends JFrame { JLabel l = new JLabel("zz"); public Main() { Container c = getContentPane(); setSize(1000, 1000); setVisible(true); c.addKeyListener(new MyKeyListener()); c.setLayout(new FlowLayout()); c.add(l); c.setFocusable(true); c.requestFocus(); } class MyKeyListener extends KeyAdapter { public void keyPressed(KeyEvent e) { int size = l.getFont().getSize(); if(e.getKeyCode() == 107) { l.setFont( new Font("Arial", Font.PLAIN, size+5) ); } else if(e.getKeyCode() == 109) { if(size-5>5) l.setFont(new Font("Arial", Font.PLAIN, size-5)); } } } public static void main(String[] args) { new Main(); } } int random_number = (int)(Math.random()*100); // 0이상 100미만의 랜덤 정수 만들기 꼭 기억하기!!!******잊어버리면 혼남!!!!!!!꼭꼮꼬꼬꼮끼억하기 * import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Main extends JFrame{ JLabel l = new JLabel("cl"); public Main() { setSize(300,300); setVisible(true); Container c = getContentPane(); l.addMouseListener(new MyMouseListener()); c.setLayout(null); c.add(l); l.setLocation(100,100); l.setSize(10, 10); } class MyMouseListener extends MouseAdapter{ public void mouseClicked(MouseEvent e) { System.out.println("ccc"); l.setLocation((int)(Math.random()*300),(int)(Math.random()*300)); } } public static void main(String[] args) { new Main(); } } */
0
0
11
15088sk1@naver.com
2022년 10월 09일
In 소스 코드 제출
/* import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Main extends JFrame { JButton b = new JButton("d"); public Main() { setTitle("dddddddddddd"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container c = getContentPane(); c.setLayout(new FlowLayout()); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (b.getText().equals("action")) b.setText("엑샨"); else b.setText("action"); } }); c.add(b); setSize(500, 500); 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 { private JLabel la = new JLabel("Hello"); public Main() { setTitle("ssdeiwqowmkejdejkqoieqwewkwkwkwkwmwmwid"); Container c = getContentPane(); c.addKeyListener(new MyKeyListener()); c.setFocusable(true); c.requestFocus(); //c.addMouseListener(new MyMouseListener()); c.setLayout(null); la.setSize(50,20); la.setLocation(1,1); c.add(la); setSize(250, 250); setVisible(true); } //extends KeyAdapter class MyKeyListener implements KeyListener{ @Override public void keyTyped(KeyEvent e) { // TODO Auto-generated method stub } @Override public void keyPressed(KeyEvent e) { int x = la.getX(); int y = la.getY(); if(e.getKeyCode()==KeyEvent.VK_RIGHT) { if(x>230) la.setLocation(0, y); else la.setLocation(x+10, y); } else if(e.getKeyCode()==KeyEvent.VK_DOWN) { if(y>210) la.setLocation(x,0); else la.setLocation(x, y+10); } else if (e.getKeyCode()==KeyEvent.VK_LEFT) { if(x<20) la.setLocation(230,y); else la.setLocation(x-10,y); } else if(e.getKeyCode()==KeyEvent.VK_UP) { if(y<20) la.setLocation(x,230); else la.setLocation(x,y-10); } if(e.getKeyChar()=='r') { la.setForeground(Color.red); } if(e.getKeyChar()=='g') { la.setForeground(Color.GRAY); } if(e.getKeyChar()=='b') { la.setForeground(Color.BLUE); } } @Override public void keyReleased(KeyEvent e) { // TODO Auto-generated method stub } } // class MyMouseListener extends MouseAdapter{ // public void mousePressed(MouseEvent e) { // int x = e.getX(); // int y = e.getY(); // la.setLocation(x, y); // // } // } public static void main(String[] args) { new Main(); } } import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Main extends JFrame{ JButton b = new JButton("java"); public Main() { setTitle("dkadka"); Container c = getContentPane(); c.setLayout(new FlowLayout()); b.addMouseListener(new MyMouseListener()); c.add(b); setSize(1000,1000); setVisible(true); } class MyMouseListener implements MouseListener{ public void mouseClicked(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mousePressed(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseReleased(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseEntered(MouseEvent e) { b.setText("Love Java"); } @Override public void mouseExited(MouseEvent e) { b.setText("사랑해"); } } public static void main(String[] args) { new Main(); } } */
0
0
3
15088sk1@naver.com
2022년 7월 28일
In 소스 코드 제출
} import java.awt.*; import javax.swing.*; import java.util.*; class Main extends JFrame{ Main(){ setVisible(true); setSize(700,700); Container c = getContentPane(); c.setLayout(new BorderLayout()); JPanel p1 = new JPanel(); p1.setBackground(Color.WHITE); p1.setLayout(null); c.add(p1,BorderLayout.CENTER); JPanel p2 = new JPanel(); p2.setBackground(Color.GRAY); c.add(p2,BorderLayout.NORTH); JButton b = new JButton("열기"); JButton b1 = new JButton("닫기"); JButton b2 = new JButton("나가기"); p2.add(b); p2.add(b1); p2.add(b2); JPanel p3 = new JPanel(); p3.setBackground(Color.YELLOW); c.add(p3,BorderLayout.SOUTH); JButton b3 = new JButton("Word input"); p3.add(b3); JTextField jt = new JTextField(10); p3.add(jt); for(int i=1;i<=10;i++) { JLabel la = new JLabel("*-*"); p1.add(la); la.setSize(15, 15); int x = (int)(Math.random()*200)+50; int y = (int)(Math.random()*200)+50; la.setLocation(x, y); la.setForeground(Color.RED); } } public static void main(String[] args) { new Main(); } } */ /* import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; import java.util.*; class Main extends JFrame{ Container c = getContentPane(); Main(){ setVisible(true); setSize(700,700); c.setLayout(null); JButton b3 = new JButton("클릭하세요!"); b3.setSize(100, 50); b3.setLocation(300, 100); b3.addActionListener(new MyActionListener()); //액션리스너를 붙여줘! c.add(b3); } class MyActionListener implements ActionListener{ int count=0; public void actionPerformed(ActionEvent e) { if(count==10) { c.removeAll(); c.repaint(); } else { count++; JLabel la = new JLabel("new label!!"); la.setSize(100, 100); int x = (int)(Math.random()*600)+50; int y = (int)(Math.random()*600)+50; la.setLocation(x, y); c.add(la); c.repaint(); //다시그리기 } //e : 이벤트에 대한 정보를 담고있는 객체 ( 이벤트가 어디서 일어났는지?(소스), 일어난 시간?, 일어난 위치) // JButton b = (JButton)e.getSource(); // if(b.getText().equals("클릭되었음!!")) // b.setText("클릭 안 됨!"); // else // b.setText("클릭되었음!!"); } } public static void main(String[] args) { new Main(); } } */ import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; import java.util.*; class Main extends JFrame{ //이벤트 리스너랑 같ㅇ이 쓸 컴포넌트는 여기에다가!! JPanel p1= new JPanel(); Main(){ Container c = getContentPane(); setVisible(true); setSize(700,700); c.setLayout(new BorderLayout()); JPanel p = new JPanel(); c.add(p,BorderLayout.NORTH); JButton b = new JButton("추가 버튼 "); b.addActionListener(new Action()); //리스너 버튼에 붙여주기 JButton b1 = new JButton("전부 삭제"); p.add(b); p.add(b1); c.add(p1,BorderLayout.CENTER); p1.setLayout(null); } class Action implements ActionListener{ public void actionPerformed(ActionEvent e) { JLabel la = new JLabel("*-*"); la.setSize(100, 100); int x = (int)(Math.random()*600)+50; int y = (int)(Math.random()*600)+50; la.setLocation(x, y); p1.add(la); p1.repaint(); } } public static void main(String[] args) { new Main(); } }
0
0
1
15088sk1@naver.com
2022년 6월 29일
In 소스 코드 제출
import java.awt.*; import javax.swing.*; import java.util.*; class Main extends JFrame{ Main(){ setTitle("진우의 뀨번째 GUI입니다"); setSize(500,300); setVisible(true); Container c = getContentPane(); //현재의 프레임을 c라고 부를게 ! //Layout 설정 //1. flowlayout FlowLayout layout = new FlowLayout(); //2. girdlayout 격자 GridLayout layout = new GridLayout(행개수,열개수); //3. BorderLayout BorderLayout layout = new BorderLayout(); c.setLayout(new FlowLayout()); //컴포넌트 생성 JButton b1 = new JButton("button1"); // JButton b2 = new JButton("button2"); // JButton b3 = new JButton("button3"); b1.setBackground(Color.YELLOW); //배경색설정 b1.setForeground(Color.RED); //글자색설정 //컨테이너에 컴포넌트 붙이기 c.add(b1); // c.add(b2); // c.add(b3); // JButton b4 = new JButton("button4"); //c.add(b4,BorderLayout.WEST); //BorderLayout일때는 NORTH, CENTER, SOUTH, WEST, EAST 중 위치를 정해줘야한다!!꼮!! JLabel la = new JLabel("ID : "); c.add(la); JTextField tf = new JTextField("여기에 아이디를 입력하세요"); c.add(tf); } public static void main(String[] args) { new Main(); } } import java.awt.*; import javax.swing.*; import java.util.*; class Main extends JFrame{ Main(){ setSize(500,300); setVisible(true); Container c = getContentPane(); JButton b1 = new JButton("ok"); JButton b2 = new JButton("cancel"); JButton b3 = new JButton("Ignore"); c.add(b1); c.add(b2); c.add(b3); FlowLayout layout = new FlowLayout( ); b1.setForeground(Color.BLUE); b2.setForeground(Color.BLUE); b3.setForeground(Color.BLUE); b1.setBackground(Color.magenta); b2.setBackground(Color.magenta); b3.setBackground(Color.magenta); c.setBackground(Color.CYAN); c.setLayout(layout); } public static void main(String[] args) { new Main(); } } */ /* import java.awt.*; import javax.swing.*; import java.util.*; class Main extends JFrame{ Main(){ setVisible(true); setSize(700,700); FlowLayout l = new FlowLayout(); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container c = getContentPane(); c.setLayout(new FlowLayout()); c.add( new JButton("add")); c.add( new JButton("sub")); c.add( new JButton("mul")); c.add( new JButton("div")); c.add( new JButton("Calculate")); } public static void main(String[] args) { new Main(); } } */ import java.awt.*; import javax.swing.*; import java.util.*; class Main extends JFrame{ Main(){ setSize(700,700); setVisible(true); Container c = getContentPane(); //c.setLayout(new FlowLayout()); c.setLayout(new GridLayout(1,10)); c.setBackground(Color.BLUE); for(int i=0;i<10;i++) { //int -> String Integer.toString(i) 정수를 문자열로 바꾸기!!꼭 기억하기~~~~!!!!! JButton b = new JButton(Integer.toString(i)); c.add(b); } } public static void main(String[] args) { new Main(); } }
0
0
2
15088sk1@naver.com
2022년 6월 22일
In 소스 코드 제출
abstract class PairMap { protected String keyArray[]; protected String valueArray[]; abstract String get(String key); abstract void put(String key, String value); abstract String delete(String key); abstract int length(); } class Dictionary extends PairMap { private int size; private int n = 0; public Dictionary(int size) { this.size = size; keyArray = new String[size]; valueArray = new String[size]; } String get(String key) { for (int i = 1; i <= n; i++) { if (keyArray[i].equals(key)) { return valueArray[i]; } } return null; } void put(String key, String value) { // 1. keyArray에 key가 있으면 기존 value 를 바꾼다 for (int i = 1; i <= n; i++) { if (keyArray[i].equals(key)) { valueArray[i] = value; return; } } // 2.기존에 keyArray에 key가 없을때 추가 n++; keyArray[n] = key; valueArray[n] = value; } String delete(String key) { String value = null ; for (int i = 1; i <= n; i++) { if (keyArray[i].equals(key)) { value=valueArray[i]; valueArray[i]=null; break; } } return value; } int length() { return n; } } class Main { public static void main(String[] args) { Dictionary dic = new Dictionary(10); v dic.put("황기태", "자바"); dic.put("이재문", "c언어"); dic.put("이재문", "파이선"); System.out.println("이재문의 값은" + dic.get("황기태")); System.out.println("황기태의 값은" + dic.get("이재문")); dic.delete("황기태"); System.out.println("황기태의 값은" + dic.get("황기태")); } }*/ interface Shape{ final double PI = 3.14; void draw(); double getArea(); default public void redraw() { System.out.println("다시 그려"); draw(); } } class Circle implements Shape { private int r; Circle(int r){ this.r = r; } public void draw() { System.out.println("반지름은"+r+"임"); } public double getArea() { return r*r*PI; } } class Oval implements Shape{ private int a,b; Oval(int a,int b){ this.a = a; this.b = b; } public void draw() { System.out.println(a+"x"+b+"타원"); } public double getArea() { return a*b*PI; } } class Rect implements Shape{ private int c,d; Rect(int c,int d){ this.c = c; this.d = d; } public void draw() { System.out.println(c+"x"+d+"사각"); } public double getArea() { return c*d; } } class Main{ public static void main(String[] args) { Shape donut = new Circle(10); Shape donu = new Oval(20,30); Shape don = new Rect(10, 40); donut.redraw(); donu.redraw(); don.redraw(); System.out.println("면"+donut.getArea()); System.out.println("men"+donu.getArea()); System.out.println("men"+don.getArea()); } }
0
0
1
15088sk1@naver.com
2022년 6월 15일
In 소스 코드 제출
import java.util.*; ////////1. interface Stack{ int length(); int capacity(); String pop(); boolean push(String val); } /////2. class StringStack implements Stack{ int size; int top=-1; //마지막으로 입력된 데이터의 위치 String stack[]; public StringStack(int size) { this.size=size; stack = new String[size]; } public int length() { return top+1; } public int capacity() { return size-(top+1); } public String pop() { return stack[top--]; } public boolean push(String val) { if(size==0) return false; else { size--; top++; System.out.println("top = " +top + "size = "+ size); stack[top]=val; return true; } } } /////3. class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("총스택저장 곤간의 크기 입력 >>"); int size = sc.nextInt(); int cnt = 0; StringStack st = new StringStack(size); while(true) { cnt++; System.out.println("문자열 입력>>"); String c = sc.next(); if(c.equals("그마")) { System.out.print("스택에 저장된 모든 문자열 팝 : "); while(st.top!=-1) { System.out.print(st.pop()+" "); } break; } if(st.push(c)==false) { System.out.println("스텍 꽉"); } } } } */ abstract class PairMap { protected String keyArray[]; protected String valueArray[]; abstract String get(String key); abstract void put(String key, String value); abstract String delete(String key); abstract int length(); } class Dictionary extends PairMap { private int size; private int n = 0; public Dictionary(int size) { this.size = size; keyArray = new String[size]; valueArray = new String[size]; } String get(String key) { //다음시간에 추가! } void put(String key, String value) { //1. keyArray에 key가 있으면 기존 value 를 바꾼다 for(int i = 0;i<n;i++) { if(keyArray[i].equals(key)) { valueArray[i] = value; return ; } } //2.기존에 keyArray에 key가 없을때 추가 n++; keyArray[n]=key; valueArray[n]=value; } String delete(String key) { //다음시간에 추가! } int length() { return n; } } class Main { public static void main(String[] args) { Dictionary dic = new Dictionary(10); dic.put("황기태", "자바"); dic.put("이재문", "c언어"); dic.put("이재문", "파이선"); System.out.println("이재문의 값은" + dic.get("황기태")); System.out.println("황기태의 값은" + dic.get("이재문")); dic.delete("황기태"); System.out.println("황기태의 값은" + dic.get("황기태")); } }
0
0
2
15088sk1@naver.com
2022년 6월 11일
In 소스 코드 제출
class ColorPoint extends Point{ private String color; ColorPoint( int x , int y , String color){ super(x,y); this.color=color; } ColorPoint(){ super(0, 0); this.color = "black"; } ColorPoint(int x,int y){ super(x,y); this.color = "black"; } void setXY(int x,int y){ move(x,y); } void setColor(String color) { this.color = color; } public String toString() { return color+"색의 ("+getX()+","+getY()+")"+"이 아니다"; } } */ /* class Point{ private int x,y; public Point(int x,int y) { this.x = x; this.y = y; } public int getX() { return x; } public int getY() { return y; } protected void move(int x,int y) { this.x = x; this.y = y; } } class Point3D extends Point{ private int z; Point3D(int x, int y, int z){ super(x,y); this.z = z; } void moveup() { z++; } void movedown() { z--; } void move(int x, int y, int z) { super.move(x, y); this.z=z; } public String toString(){ return "("+getX()+","+getY()+","+z+")"; } } class Main{ public static void main(String[] args) { Point3D p = new Point3D(1, 2, 3); System.out.println(p.toString()+"아니가 맞은가"); p.moveup(); System.out.println(p.toString()+"이지 않아"); p.movedown(); p.move(10, 10); System.out.println(p.toString()+"임 아니고 ㅇ맞고 아니고 맞고 아니고 맞고 아니고"); p.move(100, 200, 300); System.out.println(p.toString()+"임"); } } */ import java.util.*; interface Stack{ int length(); int capacity(); String pop(); boolean push(String val); } class StringStack implements Stack{ int size; int top=0; String stack[]; public StringStack(int size) { this.size=size; stack = new String[size]; } public int length() { return top; } public int capacity() { return size-top; } public String pop() { return stack[top]; } public boolean push(String val) { if(top==size) return false; else { size--; stack[top]=val; top++; return true; } } } class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("총스택저장 곤간의 크기 입력 >>"); int size = sc.nextInt(); StringStack st = new StringStack(size); while(true) { System.out.println("문자열 입력>>"); String c = sc.next(); if(c.equals("그마")) { break; } if(st.push(c)==false) { System.out.println(); } } } }
0
0
1
15088sk1@naver.com
2022년 6월 08일
In 소스 코드 제출
class IPTV { private int size; private int color; private String address; public IPTV(String address, int color,int size) { this.size = size; this.color = color; this.address = address; } protected int getSize() { return size; } protected int getColor() { return color; } protected String getAdress() { return address; } void printProperty(){ System.out.println("나의 IPTV는"+address+"주소의"+size+"인치"+color+"컬러"); } } class Main { public static void main(String[] args) { IPTV iptv = new IPTV("192.1.1.2", 2048, 32); iptv.printProperty(); } }*/ import java.util.*; class ColorPoint { private int x; private int y; private String color; public ColorPoint(int x, int y,String color) { this.x = x; this.y = y; this.color = color; } public int getX() { return x; } public int getY() { return y; } protected void move(int x, int y) { this.x = x; this.y = y; } } class setXY { ColorPoint cp = new ColorPoint(10,20,"RED"); setXY(){ cp.getX(); cp.getY(); } } class setColor extends setXY{ setColor(){ cp. } }
0
0
2
15088sk1@naver.com
2022년 6월 01일
In 소스 코드 제출
import java.util.*; abstract class Converter{ abstract protected double convert(double src); abstract protected String getSrcString(); abstract protected String getDestString(); protected double ratio; public void run() { Scanner sc = new Scanner(System.in); System.out.println(getSrcString()+"을"+ getDestString()+"로 바꿉니다."); System.out.print(getSrcString()+"을 입력하시오>>>>>>> "); double val = sc.nextDouble(); double res = convert(val); System.out.println("변환결과"+res+ getDestString()+"입니다"); sc.close(); } } class Km2Mile extends Converter{ Km2Mile(double m){ ratio = m; } protected double convert(double src) { return src/ratio; } protected String getSrcString() { return "Km"; } protected String getDestString() { return "mile"; } } class Main{ public static void main(String[] args) { Km2Mile toMile = new Km2Mile(1.6); toMile.run(); } } class Won2Dollar extends Converter{ Won2Dollar(int r){ ratio = r; } protected double convert(double src) { return src/ratio; } protected String getSrcString() { return "원"; } protected String getDestString() { return "달러"; } } class Main{ public static void main(String[] args) { Won2Dollar toDollar = new Won2Dollar(1200); toDollar.run(); } } interface Converter{ public static double ratio=1200; //상수 필드 abstract double convert(double src); //추상메소드 abstract String getSrcString();//추상메소드 abstract String getDestString();//추상메소드 } interface Converter2{ abstract double convert(double src); //추상메소드 abstract String getSrcString();//추상메소드 abstract String getDestString();//추상메소드 } class Won2Dollar imp lements Converter, Converter2{ Won2Dollar(double r){ } public double convert(double src) { return src/ratio; } public String getSrcString() { return "원"; } public String getDestString() { return "달러"; } } class Main{ public static void main(String[] args) { Won2Dollar toDollar = new Won2Dollar(1200); } } */ interface PhoneInterface { final int TIMEOUT = 10000; void sendCall(); void receiveCall(); default void printLogo() { System.out.println("** phone **"); } } interface MobilePhoneInterface extends PhoneInterface{ void sendSMS(); void receiveSMS(); } interface MP3Interface { public void play(); public void stop(); } class PDA{ public int calculate(int x,int y) { return x + y; } } class SmartPhone extends PDA implements MobilePhoneInterface,MP3Interface{ public void sendCall() { System.out.println("따르르르르르르르ㅡㄹㄹㅇ"); } public void receiveCall() { System.out.println("전화옴"); } public void sendSMS() { System.out.println("문자감"); } public void receiveSMS() { System.out.println("문자옴"); } public void play() { System.out.println("음악 연주 ㄱ"); } public void stop() { System.out.println("음악 멈"); } public void schedule() { System.out.println("일정관리"); } } public class Main{ public static void main(String[] args) { SmartPhone phone = new SmartPhone(); phone.printLogo(); phone.sendCall(); phone.play(); System.out.println("3과 5를 더하면"+ phone.calculate(3, 5)); phone.schedule(); } }
0
0
1
15088sk1@naver.com
2022년 5월 21일
In 소스 코드 제출
/*class Arrayutill { public static int[] concat(int[] a, int[] b) { int[] c = new int[a.length+b.length]; for(int i = 0 ; i<a.length ; i++) { c[i] = a[i]; } for(int i = 0 ; i<b.length ; i++) { c[i+a.length] = b[i]; } return c; } public static void print(int[] a) { System.out.print("["); for (int i = 0; i < a.length; i++) System.out.print(a[i]+" "); System.out.print("]"); } } class Main { public static void main(String[] args) { int[] array1 = { 1, 5, 7, 9 }; int[] array2 = { 3, 6, -1, 100, 77 }; int[] array3 = Arrayutill.concat(array1, array2); Arrayutill.print(array3); } } 메소드 오버라이딩 (재정의) 메소드 오버로딩 (같은 이름의 메소드이지만, 다른 매개변수를 갖는 메소드) 이름이 같은 메소드를 생성 * */ /* class Point { private int x,y; public void set(int x, int y) { this.x = x; this.y = y; } void showPoint() { System.out.println("점의 좌표는 룰루라라라라라ㅏ라라라("+x+",루루루루루루ㅜ루루루루루라라라ㅏ라라[라ㅏ"+y+")끝"); } void showPoint(int n){ //메소드 오버로딩 } } class Ee extends Point { private String color; public void setColor(String color) { this.color = color; } public void showColorpoint() { System.out.println(color); showPoint(); } void showPoint() { //오버라이딩 (재정의) System.out.println("colorpoint"); } } public class Main{ public static void main(String[] args) { Point p = new Point(); p.set(1, 2); p.showPoint(); Ee e = new Ee(); e.set(3, 4); e.setColor("red");; e.showColorpoint(); } } class Noodle{ private String color; private int size; protected void setColor(String color) { this.color=color; } Noodle (){ this.size = 10; } Noodle (String color) { this.size=50; this.color = color; } void show() { System.out.println("size : "+size); System.out.println("color : "+color); } } class Ramyun extends Noodle{ private String name; Ramyun(){ setColor("yellow"); } Ramyun(String color){ super(color); //부모의 생성자 호출시 맨 위에 작성해야함!!!! show(); } } class Main{ public static void main(String[] args) { Ramyun jin = new Ramyun(); jin.show(); Ramyun shin = new Ramyun("red"); shin.show(); } } class Point { private int x, y; public Point() { this.x = this.y = 0; } public Point(int x, int y) { this.x = x; this.y = y; } public void showPoint() { System.out.println("(" + x + "," + y + ")"); } } class ColorPoint extends Point { private String color; public ColorPoint(int x, int y, String color) { super(x, y); this.color = color; } public void showColorPoint() { System.out.println(color); showPoint(); } } public class Main{ public static void main(String[] args) { ColorPoint cp = new ColorPoint(5, 6, "blue"); cp.showColorPoint(); } } 추상클래스 : abstract 추상메소드를 포함하고 있다 -> 추상 클래스 추상클래스는 객체생성이 물가능하다. but 레퍼런스변수는 생성 가능 */ abstract class Person{ //추상 클래스 int age; String name; abstract void speak(); //추상메소드 void sleep() { System.out.println("잠자기"); } } class Student extends Person{ void speak() { //추상메소드를 오버라이딩 System.out.println("저는 학생이예요"); } } class Main{ public static void main(String[] args) { //Person p ; (o) //p = new Person(); (x) , Student s = new Student(); s.speak(); s.sleep(); } }
0
0
1
15088sk1@naver.com
2022년 5월 18일
In 소스 코드 제출
class Song{ String title; String artist; String country; int year; Song(){ this("title", "artist", "country", 1111); //자신의 다른 생성자 호출 } Song(String title,String artist ,String country,int year){ this.title = title; this.artist = artist; this.country = country; this.year = year; } void show() { System.out.println(year+"년 "+country+"국적의 "+artist+"가 부른 "+title); } } class Main{ public static void main(String[] args) { //Song sg = new Song("Dancing Queen","ABBA","스웨덴",1987); //int arr[] = new int[100]; Song sg[] = new Song[100]; for(int i=0;i<sg.length;i++) { sg[i] = new Song(); } sg[0].show(); //sg.show(); } } import java.util.*; class Book{ String title,author; Book(String title,String author){ this.title = title; this.author = author; } } public class Main{ public static void main(String[] args) { Book [] bk = new Book[2]; Scanner sc = new Scanner(System.in); for(int i = 0;i<bk.length; i++) { System.out.println("제목>>>>"); String title = sc.nextLine(); System.out.println("저자>>>>>>>>>"); String author = sc.nextLine(); bk[i] = new Book(title, author); } for(int i = 0 ; i<bk.length;i++) { System.out.println("("+bk[i].title +", "+ bk[i].author+")"); } sc.close(); } } import java.util.*; class Circle { private double x, y; private int radius; Circle(double x, double y, int radius) { this.x = x; this.y = y; this.radius = radius; } public int getR() { return radius; } public void show() { System.out.println("(" + x + "," + y + ")" + radius); } } public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Circle c[] = new Circle[3]; for (int i = 0; i < c.length; i++) { System.out.println("x,y, radius >>>"); double x = sc.nextDouble(); double y = sc.nextDouble(); int radius = sc.nextInt(); c[i] = new Circle(x, y, radius); } int max = 0; for (int i = 0; i < c.length; i++) { if(c[i].getR()>c[max].getR()) { max=i; } } System.out.println("가장 넓이가 큰 원은"); c[max].show(); } } */ class Day{ private String work; public void set(String work) { this.work = work; } public String get() { return work; } public show() { if(work == null) { System.out.println("없습니다"); } else System.out.println(work+"입니다"); } } public class Main{ public static void main(String[] args) { } }
0
0
1
15088sk1@naver.com
2022년 5월 14일
In 소스 코드 제출
import java.util.Scanner; /*class Book { String title; String author; void show() { System.out.println(title + " " + author); } public Book() { this("", ""); System.out.println("생성자 부름"); } public Book(String title) { this(title, "작자바보"); } public Book(String title, String author) { this.title = title; this.author = author; } } public class Main { public static void main(String[] args) { Book prince = new Book("어린왕자", "생텍쥐페리"); Book love = new Book("춘향전"); Book emptyBook = new Book(); love.show(); } } class Samp { int id; public void Samp(int x) { this.id = x; } public void Samp() { System.out.println("생성자 호출"); this(0); } } class TV { String a; int b; int c; TV(String a1,int b1,int c1){ a=a1; b=b1; c=c1; } void show() { System.out.println(a+"에서 만든"+b+"년형"+c+"인치 TV"); } } public class Main{ public static void main(String[] args) { TV myTV = new TV("LG", 2017 , 32); myTV.show(); } }*/ /* class pun{ private int a; int b; int c; pun(int a2,int b2 ,int c2){ a=a2; b=b2; c=c2; } int close() { return (a+b+c)/3; } void set_a(int a) { this.a = a; } void viewa() { System.out.println(a); } } public class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("수 과 미 순으로 3개 입력 >>>"); int math = sc.nextInt(); int science = sc.nextInt(); int art = sc.nextInt(); pun me = new pun(math, science, art); //me.a=10; me.set_a(10); me.viewa(); //System.out.println(me.a); System.out.println("평균은"+me.close()); } }*/
0
0
3

15088sk1@naver.com

더보기
bottom of page