[ 무료 ] 웹툰 , 이상한 것들
레이블이 지식iN인 게시물을 표시합니다. 모든 게시물 표시
레이블이 지식iN인 게시물을 표시합니다. 모든 게시물 표시

2024년 12월 21일 토요일

JSON 뭔가요? 초보를 위한 쉬운 설명

 

JSON이란?

JSON(JavaScript Object Notation)은 데이터를 표현하고 교환하기 위해 만들어진 텍스트 기반의 데이터 형식입니다. 서버와 클라이언트 간 데이터를 주고받거나, 애플리케이션 설정을 저장하는 데 자주 사용됩니다.

JSON은 간단하면서도 강력한 데이터 구조를 제공하기 때문에 웹 개발은 물론 다양한 프로그래밍 환경에서 사랑받고 있습니다.


JSON의 주요 특징

  1. 키-값 쌍으로 데이터를 표현합니다.
  2. 사람이 읽기 쉽고, 기계로 처리하기 쉽습니다.
  3. 프로그래밍 언어에 관계없이 사용 가능합니다.
  4. 데이터 구조가 가볍고 유연합니다.

JSON의 기본 구조

JSON은 두 가지 기본 데이터 구조를 지원합니다:

  1. 객체(Object): 중괄호 {}를 사용해 키-값 쌍을 저장합니다.
    예:

    { "name": "한송이", "age": 25, "isStudent": true }
  2. 배열(Array): 대괄호 []로 데이터를 리스트 형태로 저장합니다.
    예:

    [ "JavaScript", "Python", "C++" ]

위 두 가지를 조합해 복잡한 데이터를 표현할 수도 있습니다.


JSON의 실제 사용 사례

  1. 웹 API: 클라이언트와 서버 간 데이터 교환.
    예:

    { "status": "success", "message": "데이터가 성공적으로 저장되었습니다." }
  2. 구성 파일: 프로그램이나 애플리케이션의 설정을 저장.
    예:

    { "theme": "dark", "language": "ko", "autoSave": true }
  3. 데이터 저장: 데이터베이스 대용으로 사용.
    예:

    { "users": [ {"id": 1, "name": "한송이"}, {"id": 2, "name": "홍길동"} ] }

JSON의 장점과 단점

장점:

  • 간단함: 직관적인 구조로 쉽게 이해할 수 있습니다.
  • 언어 독립적: 거의 모든 언어에서 지원됩니다.
  • 호환성: 서버-클라이언트 간 데이터 전송에 최적화.

단점:

  • 유효성 검사: 잘못된 JSON 형식은 에러를 유발합니다.
  • 대용량 데이터: 데이터가 커지면 효율성이 떨어질 수 있습니다.

JSON과 자바스크립트의 관계

JSON은 자바스크립트의 객체 표기법을 기반으로 만들어졌지만, 특정 문법 규칙을 엄격히 따릅니다.

JSON을 JavaScript 객체로 변환:

javascript

const jsonString = '{"name": "한송이", "age": 25}'; const obj = JSON.parse(jsonString); console.log(obj.name); // 한송이

JavaScript 객체를 JSON 문자열로 변환:

javascript

const obj = { name: "한송이", age: 25 }; const jsonString = JSON.stringify(obj); console.log(jsonString); // {"name":"한송이","age":25}

결론

JSON은 현대 웹과 소프트웨어 개발에서 없어서는 안 될 중요한 도구입니다.
초보자도 쉽게 배울 수 있는 만큼, 오늘부터 JSON을 활용한 데이터를 다루는 연습을 시작해 보세요!

2022년 9월 15일 목요일

한글 혼합형 차트 만들기

한글 혼합형 차트 만들기

 

마우스 왼쪽버튼 클릭후 오른쪽 버튼을 눌러 이미지를 저장하세요.

이미지를 저장 후 보시면 크게 볼 수 있습니다.


아래는 한글(HWP)에서 혼합형 차트를 만드는 방법을 단계별로 정리한 내용입니다. 이를 따라하면 "키"와 "성적"과 같은 데이터를 시각적으로 표현할 수 있습니다.


1. 데이터 입력

  1. 표를 만들어 데이터를 입력합니다.
    예:
이름 성적
한송이 160 70
두송이 170 40
세송이 150 50

2. 차트 삽입

  1. 메뉴에서 차트 아이콘을 클릭합니다.
    또는 삽입 > 차트 메뉴를 선택합니다.
  2. 차트를 추가하면 데이터 입력한 표와 연결됩니다.

3. 혼합형 차트 설정

  1. 차트를 선택한 상태에서 차트 마법사를 실행합니다.
  2. 혼합형 차트를 선택합니다.
    • 예를 들어, "키"는 막대 그래프로, "성적"은 꺾은선 그래프로 표현됩니다.
  3. 미리보기 창에서 결과를 확인합니다.

4. 차트 축 추가 및 편집

  1. 차트를 우클릭하고 차트 속성을 선택합니다.
  2. 보조 축을 추가합니다.
    • 예: "성적" 데이터를 보조 축에 연결하여 막대와 꺾은선 그래프를 적절히 구분합니다.

5. 모양 및 서식 설정

  1. 차트를 선택한 후 모양 편집 메뉴를 엽니다.
  2. 값 축 범위를 설정합니다.
    • 예: 성적의 최대값(100)과 최소값(0)을 입력.
  3. 그래프 색상, 선 굵기, 마커 스타일 등을 변경하여 시각적으로 명확하게 표현합니다.

6. 최종 확인

  1. 데이터를 다시 확인하고 필요 시 차트를 조정합니다.
  2. 완료된 차트를 문서에 삽입하거나 이미지를 저장하여 사용합니다.

추가 팁

  • 색상: "키"는 파란색, "성적"은 빨간색으로 설정하면 두 데이터의 차이를 쉽게 구별할 수 있습니다.
  • 레이블: 데이터 레이블을 추가하여 정확한 값을 표시하세요.
  • 선 스타일: 꺾은선 그래프의 선을 점선으로 변경하여 막대 그래프와 차별화하세요.

[ 무료 ] 웹툰 & 이상한 것들

2012년 2월 27일 월요일

bada 2.0 펌웨어 업데이트

저의 경우는 공모전 때문에 2.0으로 유출펌업했는데요.

개발이 목적이라면 필 업하시고요. 아니시면 그냥 정식나오면 하시는 것이 좋을 것 같습니다.
유출펌업해서 정식업 안될 것 같아서 좀 걱정 되고요.
펌업하다가 벽돌 될 까봐 또 걱정무지 되었습니다, 그 기다리는 시간이 엄청 공포스러워요.
속도는 차이없고요. 화면은 좀 깔금하고 좋아요.

저는 여기서 펌업했습니다.

참고) 벽돌되어도 저는 책임없어요. ㅎ~

http://www.badaforums.net/forums/bada-firmware/firmware-flashing-guide-video-how-flash-the-wave-t1370.html

인증샷

제가 만든앱입니다.
혹 보시면 다운로드 해주시고 별 다섯개(10점) 빵빵하게 좀 주세요. ㅎㅎㅎㅎㅎ
 
2012 년 무료 입니다.ㅋ

2008년 10월 24일 금요일

MS 엑셀 vba Macro Formula ,Value , FormulaR1C1 차이점


Public Sub Macro()
'결과의 차이는없습니다
Range("A1").FormulaR1C1 = "100"
Range("B1").Formula = "100"
Range("C1").Value = "100"

'하지만 다음과 같은 차이점이있습니다.
'FormulaR1C1 수식을 R1C1 방식으로 반환
'Formul 수식은 A1 방식을 반환
'Value 수식 계산 결과를 반환
Range("a2").Value = "=sum(a1:c1)"
Debug.Print Range("a2").FormulaR1C1
Debug.Print Range("a2").Formula
Debug.Print Range("a2").Value

'값 설정시에서는 FormulaR1C1 방식은 R1C1 방식이어야 합니다.
Range("b2").FormulaR1C1 = "=sum(R[-1]C[-1]:R[-1]C[1])"
'Range("b2").FormulaR1C1 = "=sum(a1:c1)"
Range("b3").Formula = "=sum(a1:c1)"
Range("b4").Value = "=sum(a1:c1)"

End Sub

맞춤훈련 파이팅

2008년 9월 4일 목요일

java font




import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
import javax.xml.crypto.Data;
import java.io.*;
import java.lang.reflect.Array;
import java.awt.CheckboxMenuItem;
import java.util.Calendar;
import java.awt.Font;
public class NotePad2Frame extends JFrame //implements TextListener
{
private ActionListener listener;
private TextListener txlistener;
private Font font;
JMenuBar bar;

JMenuItem NPrint,NClock,NFile,NEdit,NTool,NSave,NHelp,NExit,NFind,NChange,HTML,Def;
private Dialog d,dl;
private FileDialog fd;
private JTextPane Area;
private JLabel label;
private JPanel panel;
String str = "새문서";
String facename = "bold";


public NotePad2Frame()
{

bar = new JMenuBar();
JMenu file = new JMenu("FILE");
NFile = new JMenuItem("새문서");
NFile.setAccelerator(KeyStroke.getKeyStroke('N',Event.CTRL_MASK));
NFile.addActionListener(listener);
NEdit = new JMenuItem("불러오기");
NEdit.setAccelerator(KeyStroke.getKeyStroke('O',Event.CTRL_MASK));
NEdit.addActionListener(listener);
NTool = new JMenuItem("저장하기");
NTool.addActionListener(listener);
NTool.setAccelerator(KeyStroke.getKeyStroke('S',Event.CTRL_MASK));
JMenuItem NSave = new JMenuItem("다른이름으로저장");
NSave.addActionListener(listener);
NSave.setAccelerator(KeyStroke.getKeyStroke('A',Event.CTRL_MASK));
JMenuItem NPrint = new JMenuItem("인쇄");
NPrint.addActionListener(listener);
NPrint.setAccelerator(KeyStroke.getKeyStroke('P',Event.CTRL_MASK));
JMenuItem NExit = new JMenuItem("종료");
NExit.setAccelerator(KeyStroke.getKeyStroke('X',Event.CTRL_MASK));
NExit.addActionListener(listener);

file.add(NFile);
file.add(NEdit);
file.add(NSave);
//file.add(NHelp);
file.add(NPrint);
file.addSeparator();
file.add(NExit);

bar.add(file);
setJMenuBar(bar);

//여기까지 파일메뉴

JMenu edit = new JMenu("EDIT");
JMenuItem NFind = new JMenuItem("찾기");
NFind.setAccelerator(KeyStroke.getKeyStroke('F',Event.CTRL_MASK));
NFind.addActionListener(listener);
JMenuItem NChange = new JMenuItem("바꾸기");
NChange.setAccelerator(KeyStroke.getKeyStroke('W',Event.CTRL_MASK));
NChange.addActionListener(listener);
JMenuItem NSelectAll = new JMenuItem("모두선택");
NSelectAll.setAccelerator(KeyStroke.getKeyStroke('A',Event.CTRL_MASK));
NSelectAll.addActionListener(listener);
JMenuItem NClock = new JMenuItem("시간/날짜");
NClock.setAccelerator(KeyStroke.getKeyStroke("F5"));
edit.add(NFind);
edit.add(NChange);
edit.add(NSelectAll);
edit.add(NClock);

bar.add(edit);
setJMenuBar(bar);
//여기까지 Edit메뉴

JMenu Formula = new JMenu("FORMULA");
JMenuItem LineChange = new JMenuItem("자동 줄 바꿈");
LineChange.setAccelerator(KeyStroke.getKeyStroke('H',Event.ALT_MASK));
LineChange.addActionListener(listener);
JMenuItem NFont = new JMenuItem("글 꼴");
NFont.setAccelerator(KeyStroke.getKeyStroke('F',Event.ALT_MASK));
NFont.addActionListener(listener);

Formula.add(LineChange);
Formula.add(NFont);

bar.add(Formula);
setJMenuBar(bar);
//여기까지 서식(Formula)메뉴

JMenu Tool = new JMenu("TOOL");
JMenuItem HTML = new JMenuItem("html");

JMenuItem Def = new JMenuItem("사용자정의");
Def.addActionListener(listener);

Tool.add(HTML);
Tool.add(Def);

bar.add(Tool);
setJMenuBar(bar);
//여기까지 속성메뉴
setLayout(new BorderLayout());
Area = new JTextPane();
//Area.addTextListener(txlistener);

Area.setCaretColor(Color.blue);
Area.setSelectedTextColor(Color.green);
Area.setSelectionColor(Color.BLUE);
Area.setBackground(Color.green);
Area.setFont(new Font(null,font.ITALIC,15));
//Font클래스는 import를 할경우 선언을 안하고 사용이 가능하지만 Font의 static변수는
//전역변수로 꼭!! 선언을 하고 사용한다.!!!!!!!!!!!!!!!!!

add("Center",Area);

setVisible(true);


NFile.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Area.setText("");
}
});
NEdit.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
fd = new FileDialog(NotePad2Frame.this, "OPEN",FileDialog.LOAD); //LOAD대신 SAVE를 쓰면 저장하기다이얼로그
fd.setSize(300,200); //윈2000에서 다이얼로그 창이 빨리 사라지면 제목을 영어로 써주면됨.
fd.setVisible(true);
fd.getFile(); //파일명 알아내기
fd.getDirectory();//파일 경로알아내기

try{
FileReader fr = new FileReader(fd.getDirectory()+fd.getFile());
BufferedReader br = new BufferedReader(fr);

Area.setText("");
for(String str; (str = br.readLine()) != null;)
{
Area.setText(str + "\n");
}

br.close();
String fileName1 = fd.getFile(); //제목줄에 파일이름 붙이기;
setTitle(fileName1);

}catch(Exception ex){
JOptionPane.showMessageDialog(null, ex.getMessage());
}
}
});

/* NTool.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if()

}
});*/

NSave.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
fd = new FileDialog(NotePad2Frame.this, "OPEN",FileDialog.LOAD); //LOAD대신 SAVE를 쓰면 저장하기다이얼로그
fd.setSize(300,200); //윈2000에서 다이얼로그 창이 빨리 사라지면 제목을 영어로 써주면됨.
fd.setVisible(true);
fd.getFile(); //파일명 알아내기
fd.getDirectory();//파일 경로알아내기

try{
FileWriter fw = new FileWriter(fd.getDirectory()+fd.getFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write(Area.getText());
String filename1 = fd.getFile();
setTitle(filename1);

}catch(Exception ex)
{JOptionPane.showMessageDialog(null, ex.getMessage());}
}
});
NPrint.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
PrintJob pj;
//pj = Toolkit.getDefaultToolkit().getPrintJob(this, "hi", null);
}
});



NPrint.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try
{
Area.print();
}
catch (Exception ex){}

}
});


NExit.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
JFrame fr = new JFrame();

JLabel lb = new JLabel("종료하시겠습니까");
//
JPanel pn = new JPanel();
JButton button1 = new JButton("YES?");
button1.addActionListener(listener);
JButton button2 = new JButton("NO?");
button2.addActionListener(listener);
pn.add(button1);
pn.add(button2);

//

fr.add(lb,BorderLayout.NORTH);
fr.add(pn,BorderLayout.CENTER);
fr.setSize(200,100);
fr.setVisible(true);
fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


}
});
//여기까지 파일메뉴

NFind.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
JFrame f = new JFrame();
f.setVisible(true);
f.setSize(400,200);
f.setDefaultCloseOperation(EXIT_ON_CLOSE);

JPanel pn = new JPanel();

JLabel lb = new JLabel("찾을내용");
final JTextField jd = new JTextField(15);
JButton button1 = new JButton("다음찾기");

button1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
//String fieldString = jd.getText();
//String textstring = Area.getText();

//if(textstring.indexOf(fieldString)!=-1)
//{

//}
if(Area.getText().indexOf(jd.getText())!=-1) {
Area.select(Area.getText().indexOf(jd.getText()),Area.getText().indexOf(jd.getText())+jd.getText().length());
}
//select()메서드는 해당블락을 표시해준다!!!

java.awt.Container com = null;
com = ((javax.swing.JButton)e.getSource()).getParent();
//component의 getParent메서드를 이용해서 JFrame(찾기프레임)을 찾습니다.
while(!com.getClass().getSimpleName().equals("JFrame")){
com = com.getParent();
}
javax.swing.JFrame comFrame = (javax.swing.JFrame)com;
//해당 프레임을 닫아줍니다.
comFrame.setVisible(false);
comFrame.dispose();


}
});




pn.add(lb);
pn.add(jd);
pn.add(button1);
add(pn,BorderLayout.NORTH);

//1행

JRadioButton jb = new JRadioButton("위로");
JRadioButton jb2 = new JRadioButton("아래로");

JButton button2 = new JButton("취소");


f.add(pn);
}
});



NChange.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{

JFrame f = new JFrame("바꾸기");
f.setVisible(true);
f.setSize(400,150);
f.setDefaultCloseOperation(EXIT_ON_CLOSE);

JPanel pn = new JPanel();
JPanel pn2 = new JPanel();
JButton bt = new JButton("바꾸기");

JLabel lb1 = new JLabel("찾을 내용");
JLabel lb2 = new JLabel("바꿀 내용");
final JTextField jd = new JTextField(15);
final JTextField jd2 = new JTextField(15);
pn.add(lb1);
pn.add(jd);
pn.add(bt);
f.add(pn,BorderLayout.NORTH);


pn2.add(lb2);
pn2.add(jd2);
f.add(pn2,BorderLayout.CENTER);

bt.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String s = jd.getText();
String s2 = jd2.getText();
//indexOf() 꼭 기억하자!!!! replaceAll()마찬가지!!!
if(Area.getText().indexOf(s)!=-1){
Area.setText(Area.getText().replaceAll(s, s2));
}


}
});
}
});

NSelectAll.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Area.selectAll();
}
});


NClock.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{

Calendar cal = Calendar.getInstance();
//현재시각을 사용하기 위하여 getInstance()메서드 사용!!!!
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH);
int day= cal.get(Calendar.DAY_OF_MONTH);
int hour = cal.get(Calendar.HOUR);
int minutes = cal.get(Calendar.MINUTE);
int second = cal.get(Calendar.SECOND);


Area.setText(Area.getText()+year+"년"+month+"월"+day+"일"+hour+"시"
+minutes+"분"+second+"초");

}
});

//여기까지 EDIT메뉴~~

LineChange.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
int j=JOptionPane.showConfirmDialog(null,"자동줄바꿈을 설정하시겠습니까?"
,"자동줄 바꿈",JOptionPane.YES_NO_OPTION);

if(j!=0)
{
//
}
}

});

NFont.addActionListener(new ActionListener()
{
int fontstyle;
int size = 15;
String o;
String t;

JLabel lb;
public void actionPerformed(ActionEvent e)
{


JFrame frame = new JFrame("글 꼴");



/*JPanel pn1 = new JPanel();
JComboBox box1 = new JComboBox();

box1.addItem("궁서체");
box1.addItem("굴림체");
box1.addItem("고딕체");

*/

JPanel pn2= new JPanel();
///////////////////수정1/////////////////////////
////////////////////////////////////////////////
////////////////////////////////////////////////
//final를 추가하세요. 님이 만든 소스를 사용하다보니...
final JComboBox box2 = new JComboBox();

box2.addItem("bold");
box2.addItem("italic");
box2.addItem("type_1");
box2.addItem("truetype");

JPanel pn3 = new JPanel();
final JTextField box3 = new JTextField(10); //JTextField를 final로 선언한다!!

//box1.setEditable(true);
box2.setEditable(true);
box3.setEditable(true);

//pn1.add(box1);
pn2.add(box2);
pn3.add(box3);




//pn1.setBorder(new TitledBorder(new EtchedBorder(Color.BLUE,Color.DARK_GRAY),"글 꼴"));
pn2.setBorder(new TitledBorder(new EtchedBorder(Color.BLUE,Color.DARK_GRAY),"글꼴 스타일"));
pn3.setBorder(new TitledBorder(new EtchedBorder(Color.BLUE,Color.DARK_GRAY),"크 기"));

frame.setLayout(new GridLayout(2,1));
//frame.add(pn1);
frame.add(pn2);
frame.add(pn3);

JPanel pn4 = new JPanel();
lb = new JLabel("ABCDEF");

pn4.add(lb);
pn4.setBorder(new TitledBorder(new EtchedBorder(Color.BLUE,Color.DARK_GRAY),"미리보기"));
frame.add(pn4);

frame.setSize(400,300);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//////////////////////////////////////////// 요 부 분 !!!!!!!!!!! ///////////////////////////////
box2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{

/*
이부분 삭제하세요
o = e.getActionCommand();

if (o=="bold") {fontstyle = font.BOLD;}
else if(o=="italic"){fontstyle = font.ITALIC;}
else if(o=="type_1"){fontstyle = font.TYPE1_FONT;}
else if(o=="truetype"){fontstyle = font.TRUETYPE_FONT;}
*/
///////////////////////수정2/////////////////////
////////////////////////////////////////////////
////////////////////////////////////////////////
// 이부분 추가하세요
if(e.getSource() == box2){
JComboBox cb = (JComboBox)e.getSource();
// cb.getSelectedIndex() 이것이 0,1,2.. 값을 리턴합니다.
// 의문점 쪽지주세요
switch (cb.getSelectedIndex()) {
case 0:
fontstyle = font.BOLD;
break;
case 1:
fontstyle = font.ITALIC;
break;
case 2:
fontstyle = font.TYPE1_FONT;
break;
case 3:
fontstyle = font.TRUETYPE_FONT;

}
}
setSampleFont();


}
});


box3.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
t = box3.getText();
size = Integer.parseInt(t);
setSampleFont();
}
});


}
public void setSampleFont()
{
lb.setFont(new Font(null,fontstyle,size));
}


});


//여기까지 Formula(서식)메뉴~~

Def.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
JOptionPane.showMessageDialog(null, "2008/10/x 드디어 완성 ㅋㅋㅋ","메모장",JOptionPane.INFORMATION_MESSAGE );
}
});

}

public static void main(String args[])
{

JFrame frame = new NotePad2Frame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("메모장");
frame.setVisible(true);
frame.setSize(700,500);
}
}
/*문]
* ////////////////////////////// 요 부분 ///////////////
* 이라고 표시된 부분이 글꼴의 폰트를 변경시키는 부분인데요.
* 폰트가 딱 한번만 변경이 되고 다시 변경을 시킬때는 적용이 안되네요 ㅠㅠ
* 예를 들면 폰트를 ITALIC으로 변경을 시키면 변경이 됩니다.
* 하지만 ITALIC을 다시 BOLD로 변경을 시킬려면 적용이 안되네요.
* 왜 그런지 계속 고민을 하는데 잘안되네요.
* 고수님들의 도움좀 부탁드려여~~
*/

2008년 8월 29일 금요일

자바 JComboBox




import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

class GraphicTest extends JFrame implements ActionListener {

JLabel x1L, y1L, x2L, y2L, z1L, z2L;
JTextField x1T, y1T, x2T,y2T,z1T,z2T;
JCheckBox fill;
JRadioButton line, circle, rect, rectR, arc; // 선 원 사각형 둥근사각형 호
JButton draw; // 2개의 패널 생성 위,아래
DrCanvas can;
JComboBox combo;
////////////////////////////////////
//color 추가하세요
Color Color;
public GraphicTest(){
x1L = new JLabel("x1");
y1L = new JLabel("y1");
x2L = new JLabel("x2");
y2L = new JLabel("y2");
z1L = new JLabel("z1");
z2L = new JLabel("z2");

x1T = new JTextField("100",3);
y1T = new JTextField("50",3);
x2T = new JTextField("150",3);
y2T = new JTextField("130",3);
z1T = new JTextField("50",3);
z2T = new JTextField("50",3);

line = new JRadioButton("선");
circle = new JRadioButton("원");
rect = new JRadioButton("사각형",true);
rectR = new JRadioButton("둥근사각형");
arc = new JRadioButton("호");

ButtonGroup bg = new ButtonGroup(); // RadioButton은 항상 그룹으로 묶어줘야된다.
bg.add(line);
bg.add(circle);
bg.add(rect);
bg.add(rectR);
bg.add(arc);


draw = new JButton("그리기");

can = new DrCanvas();

fill = new JCheckBox("채우기", true);

String[] color = {"빨강","파랑","노랑","초록","흰색"};
combo = new JComboBox(color);

JPanel p = new JPanel();

p.add(x1L);
p.add(x1T);
p.add(y1L);
p.add(y1T);
p.add(x2L);
p.add(x2T);
p.add(y2L);
p.add(y2T);
p.add(z1L);
p.add(z1T);
p.add(z2L);
p.add(z2T);

p.add(fill);

JPanel p2 = new JPanel();

p2.add(line);
p2.add(circle);
p2.add(rect);
p2.add(rectR);
p2.add(arc);
p2.add(combo);
p2.add(draw);

this.add("South",p2);
this.add("North",p);
this.add("Center",can);


setSize(600,300);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);

//이벤트 처리
draw.addActionListener(this);
combo.addActionListener(this);
} // GraphicTest()

public void actionPerformed(ActionEvent e) {
////////////////////////////////////////////
// 이부분 추가하세요
if(e.getSource() == combo){

JComboBox cb = (JComboBox)e.getSource();
// cb.getSelectedIndex() 이것이 0,1,2.. 값을 리턴합니다.
// 의문점 쪽지주세요
switch (cb.getSelectedIndex()) {
case 0:
Color=Color.red;
break;
case 1:
Color=Color.blue;
break;
case 2:
Color=Color.yellow;
break;
case 3:
Color=Color.GREEN;
break;
case 4:
Color=Color.white;

}


}

can.repaint();

}// ActionEvent


class DrCanvas extends Canvas{



public DrCanvas(){

this.setBackground(new Color(140,60,80)); // 캔버스 색
this.setForeground(new Color(255,255,255)); // 도형 색상

} //DrCanvas()

public void paint(Graphics g){

//좌표 얻어오기
int x1 = Integer.parseInt(x1T.getText().trim());
int y1 = Integer.parseInt(y1T.getText().trim());
int x2 = Integer.parseInt(x2T.getText().trim());
int y2 = Integer.parseInt(y2T.getText().trim());
int z1 = Integer.parseInt(z1T.getText().trim());
int z2 = Integer.parseInt(z2T.getText().trim());

System.out.println();


System.out.println("그리기 시작" );

// 도형 그리자
if(fill.isSelected() ) { // 채우기 선택
/////////////////////////////////////////////
// 이부분 추가하세요
g.setColor(Color);

if( line.isSelected() )
g.drawLine(x1,y1,x2,y2);

else if( circle.isSelected() )
g.fillOval(x1,y1,x2,y2);

else if( rect.isSelected() )
g.fillRect(x1,y1,x2,y2);

else if( rectR.isSelected() )
g.fillRoundRect(x1,y1,x2,y2,z1,z2);

else if( arc.isSelected() )
g.fillArc(x1,y1,x2,y2,z1,z2);
} // if

else { // 채우기 해제
if(line.isSelected() ) {
g.drawLine(x1,y1,x2,y2);

} else if(circle.isSelected() ) {
g.drawOval(x1,y1,x2,y2);

} else if(rect.isSelected() ) {
g.drawRect(x1,y1,x2,y2);

} else if(rectR.isSelected() ) {
g.drawRoundRect(x1,y1,x2,y2,z1,z2);

} else if(arc.isSelected() ) {
g.drawArc(x1,y1,x2,y2,z1,z2);
}

} // else
} // paint()
} // DrCanvas()



public static void main(String[] args) {
new GraphicTest();
}
}

/*
문]
String[] color = {"빨강","파랑","노랑","초록","흰색"};
combo = new JComboBox(color);
이렇게 넣어놓으면 선택된 박스의 값을 어떻게 가져오나요...
System.out.println(combo) 라고 하니까 아주 긴 여러가지가
저기 빨강이 color[0] 이자나용 그럼 이 0 을 가져오고싶습니다...
*/

-


Sidewinder


World


FishMusic


LaughingBaby