import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class JTabbedPaneEx extends JFrame{
ImageIcon icon1, icon2, icon3, tabicon;
JButton b1, b2, b3;
JTabbedPane jp;
public JTabbedPaneEx(){
super("JTabbedPane 테스트");
icon1=new ImageIcon("../../images/image3.gif");
icon2=new ImageIcon("../../images/image2.gif");
tabicon=new ImageIcon("../../images/image1.gif");
b1=new JButton("사진1",icon1);
b2=new JButton("사진2",icon2);
jp=new JTabbedPane();
jp.addTab("탭1",new ImageIcon(""),b1);
jp.addTab("탭2",new JPanel().add(new JTextArea(7,20)));
jp.addTab("탭3",tabicon, b2,"탭사진도 추가 했습니다");
add(jp);
setBounds(300,300,300,300);
setVisible(true);
}
public static void main(String[] args){
new JTabbedPaneEx();
}
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.table.*;
public class JTableEx extends JFrame{
JTable table;
JTableModel model; //사용자 모델정의 클래스
public JTableEx(){
model = new JTableModel();
table = new JTable(model);
add(new JScrollPane(table)); //스크롤바 생성하면서
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 프로그램 종료 : JFrame갖고 있다.
setBounds(200,200,300,300);
setVisible(true);
}
public static void main(String[] args){
new JTableEx();
}
}
class JTableModel extends AbstractTableModel{ // java.swing의 추상클래스
Object[][] data={{"Nari","마루치",new Integer(1234), "옆집친구"},
{"One","오윤아",new Integer(1111), "예쁜이"},
{"two","오윤서",new Integer(2222), "귀염둥이"},
{"three","아라치",new Integer(3333), "동아리친구"}};
String[] name ={"아이디","이름","비밀번호","구분"}; //필드명 들
public int getColumnCount(){ // 테이블의 열의 수[필수]
return name.length; // return 4; 와 동일
}
public int getRowCount(){ // 테이블의 행의 수[필수]
return data.length;
}
public Object getValueAt(int r, int c){ // 실제 데이터 추출[필수]
return data[r][c];
}
public boolean isCellEditable(int r, int c){ // 테이블 편집가능하게 한다.
return (c != 0 ) ? true:false ;
}
public String getColumnName(int c){ // 테이블의 타이들명 부여
return name[c];
}
public void setValueAt(Object obj, int r, int c){ // 테이블의 필드 값 입력으로 값이 변함
data[r][c]=obj;
}
}
import java.awt.Rectangle;
import java.util.Vector;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
public class JTableEx2 extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JScrollPane jScrollPane = null;
private JTable jTable = null;
/**
* This method initializes jScrollPane
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getJScrollPane() {
if (jScrollPane == null) {
jScrollPane = new JScrollPane();
jScrollPane.setBounds(new Rectangle(14, 46, 627, 339));
jScrollPane.setViewportView(getJTable());
jScrollPane.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent e) {
}
});
}
return jScrollPane;
}
/**
* This method initializes jTable
*
* @return javax.swing.JTable
*/
private JTable getJTable() {
if (jTable == null) {
Vector columnNames = new Vector();
columnNames.add("First Name");
columnNames.add("Last Name");
columnNames.add("Sport");
columnNames.add("# of Years");
columnNames.add("Vegetarian");
Vector data = new Vector();
Vector data1 = new Vector();
data1.add("Mary");
data1.add("Campione");
data1.add("Snowboarding");
data1.add(new Integer(5));
data1.add(new Boolean(false));
Vector data2 = new Vector();
data2.add("Alison");
data2.add("Huml");
data2.add("Rowing");
data2.add(new Integer(3));
data2.add(new Boolean(true));
Vector data3 = new Vector();
data3.add("Kathy");
data3.add("Walrath");
data3.add("Knitting");
data3.add(new Integer(2));
data3.add(new Boolean(false));
Vector data4 = new Vector();
data4.add("Sharon");
data4.add("Zakhour");
data4.add("Speed reading");
data4.add(new Integer(20));
data4.add(new Boolean(true));
Vector data5 = new Vector();
data4.add("Philip");
data4.add("Milne");
data4.add("Pool");
data4.add(new Integer(10));
data4.add(new Boolean(false));
data.add(data1);
data.add(data2);
data.add(data3);
data.add(data4);
data.add(data5);
jTable = new JTable(data, columnNames);
jTable.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent e) {
System.out.println("열번호 : " + jTable.getSelectedColumn()); // TODO Auto-generated Event stub mouseClicked()
System.out.println("행번호 : " + jTable.getSelectedRow());
System.out.println("데이터 : " + jTable.getValueAt(jTable.getSelectedRow(), jTable.getSelectedColumn()));
}
});
}
return jTable;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JTableEx1 thisClass = new JTableEx1();
thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
thisClass.setVisible(true);
}
});
}
/**
* This is the default constructor
*/
public JTableEx2() {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(666, 423);
this.setContentPane(getJContentPane());
this.setTitle("JFrame");
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(getJScrollPane(), null);
}
return jContentPane;
}
} // @jve:decl-index=0:visual-constraint="10,10"
import javax.swing.SwingUtilities;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.Dimension;
import javax.swing.JScrollPane;
import java.awt.Rectangle;
import javax.swing.JTable;
public class JTableEx3 extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JScrollPane jScrollPane = null;
private JTable jTable = null;
/**
* This method initializes jScrollPane
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getJScrollPane() {
if (jScrollPane == null) {
jScrollPane = new JScrollPane();
jScrollPane.setBounds(new Rectangle(14, 46, 627, 339));
jScrollPane.setViewportView(getJTable());
jScrollPane.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent e) {
}
});
}
return jScrollPane;
}
/**
* This method initializes jTable
*
* @return javax.swing.JTable
*/
private JTable getJTable() {
if (jTable == null) {
jTable = new JTable();
jTable.setModel(new DataTableModel1());
jTable.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent e) {
System.out.println("열번호 : " + jTable.getSelectedColumn()); // TODO Auto-generated Event stub mouseClicked()
System.out.println("행번호 : " + jTable.getSelectedRow());
System.out.println("데이터 : " + jTable.getValueAt(jTable.getSelectedRow(), jTable.getSelectedColumn()));
}
});
}
return jTable;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JTableEx1 thisClass = new JTableEx1();
thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
thisClass.setVisible(true);
}
});
}
/**
* This is the default constructor
*/
public JTableEx3() {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(666, 423);
this.setContentPane(getJContentPane());
this.setTitle("JFrame");
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(getJScrollPane(), null);
}
return jContentPane;
}
} // @jve:decl-index=0:visual-constraint="10,10"
import javax.swing.*;
import java.util.Vector;
public class JTreeEx extends JFrame {
Object[] gen ={"프로그램", "System","Design"};
Vector<Vector> node1 = new Vector<Vector>() {
public String toString(){
return "Lesson";
}
};
Vector<String> node2 = new Vector<String>(){
public String toString(){
return "Java";
}
};
Vector<String> node3 = new Vector<String>(){
public String toString(){
return "XML";
}
};
public JTreeEx(){
node1.addElement(node2);
node1.addElement(node3);
node2.addElement("Beg");
node2.addElement("Adv");
node2.addElement("JSP");
node3.addElement("XSLT");
node3.addElement("DOM");
gen[0]=node1;
JTree tree = new JTree(gen); //트리구조에 상위인"gen" 추가
tree.setRootVisible(true); // 루트 설정
JScrollPane js=new JScrollPane(tree);
add(js);
setBounds(300,150,400,300);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 프로그램 종료 : JFrame갖고 있다.
}
public static void main(String[] args) {
new JTreeEx();
}
}
import javax.swing.SwingUtilities;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.Dimension;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JTextArea;
import java.awt.Font;
public class SortingEx1 extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JPanel jPanel = null;
private JPanel jPanel1 = null;
private JTextField num01 = null;
private JTextField num03 = null;
private JTextField num02 = null;
private JTextField num04 = null;
private JTextField num05 = null;
private JTextField num06 = null;
private JTextField num07 = null;
private JTextField num08 = null;
private JTextField num09 = null;
private JTextField num10 = null;
private JButton jButton = null;
private JTextArea jTextArea = null;
/**
* This method initializes jPanel
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel() {
if (jPanel == null) {
GridLayout gridLayout = new GridLayout();
gridLayout.setRows(1);
jPanel = new JPanel();
jPanel.setLayout(gridLayout);
jPanel.add(getNum01(), null);
jPanel.add(getNum02(), null);
jPanel.add(getNum03(), null);
jPanel.add(getNum04(), null);
jPanel.add(getNum05(), null);
jPanel.add(getNum06(), null);
jPanel.add(getNum07(), null);
jPanel.add(getNum08(), null);
jPanel.add(getNum09(), null);
jPanel.add(getNum10(), null);
jPanel.add(getJButton(), null);
}
return jPanel;
}
/**
* This method initializes jPanel1
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel1() {
if (jPanel1 == null) {
jPanel1 = new JPanel();
jPanel1.setLayout(new BorderLayout());
jPanel1.add(getJTextArea(), BorderLayout.CENTER);
}
return jPanel1;
}
/**
* This method initializes num01
*
* @return javax.swing.JTextField
*/
private JTextField getNum01() {
if (num01 == null) {
num01 = new JTextField();
}
return num01;
}
/**
* This method initializes num03
*
* @return javax.swing.JTextField
*/
private JTextField getNum03() {
if (num03 == null) {
num03 = new JTextField();
}
return num03;
}
/**
* This method initializes num02
*
* @return javax.swing.JTextField
*/
private JTextField getNum02() {
if (num02 == null) {
num02 = new JTextField();
}
return num02;
}
/**
* This method initializes num04
*
* @return javax.swing.JTextField
*/
private JTextField getNum04() {
if (num04 == null) {
num04 = new JTextField();
}
return num04;
}
/**
* This method initializes num05
*
* @return javax.swing.JTextField
*/
private JTextField getNum05() {
if (num05 == null) {
num05 = new JTextField();
}
return num05;
}
/**
* This method initializes num06
*
* @return javax.swing.JTextField
*/
private JTextField getNum06() {
if (num06 == null) {
num06 = new JTextField();
}
return num06;
}
/**
* This method initializes num07
*
* @return javax.swing.JTextField
*/
private JTextField getNum07() {
if (num07 == null) {
num07 = new JTextField();
}
return num07;
}
/**
* This method initializes num08
*
* @return javax.swing.JTextField
*/
private JTextField getNum08() {
if (num08 == null) {
num08 = new JTextField();
}
return num08;
}
/**
* This method initializes num09
*
* @return javax.swing.JTextField
*/
private JTextField getNum09() {
if (num09 == null) {
num09 = new JTextField();
}
return num09;
}
/**
* This method initializes num10
*
* @return javax.swing.JTextField
*/
private JTextField getNum10() {
if (num10 == null) {
num10 = new JTextField();
}
return num10;
}
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setText("정렬하기");
jButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
//System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
jTextArea.setText("");
int[] iData = new int[10];
iData[0] = Integer.parseInt(num01.getText());
iData[1] = Integer.parseInt(num02.getText());
iData[2] = Integer.parseInt(num03.getText());
iData[3] = Integer.parseInt(num04.getText());
iData[4] = Integer.parseInt(num05.getText());
iData[5] = Integer.parseInt(num06.getText());
iData[6] = Integer.parseInt(num07.getText());
iData[7] = Integer.parseInt(num08.getText());
iData[8] = Integer.parseInt(num09.getText());
iData[9] = Integer.parseInt(num10.getText());
for(int i=0 ; i<iData.length-1; i++) {
for(int j=0 ; j<iData.length-1-i ; j++) {
if(iData[j] > iData[j+1]) {
int temp = iData[j+1];
iData[j+1] = iData[j];
iData[j] = temp;
}
}
String result = (i+1) + " 회전 : ";
for(int x=0 ; x<iData.length ; x++) {
result += iData[x] + ", ";
}
jTextArea.append(result + "\n");
}
}
});
}
return jButton;
}
/**
* This method initializes jTextArea
*
* @return javax.swing.JTextArea
*/
private JTextArea getJTextArea() {
if (jTextArea == null) {
jTextArea = new JTextArea();
jTextArea.setEditable(false);
jTextArea.setFont(new Font("Baekmuk Gulim", Font.BOLD, 14));
}
return jTextArea;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
SwingUtilities.invokeLater(new Runnable() {
public void run() {
SortingEx1 thisClass = new SortingEx1();
thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
thisClass.setVisible(true);
}
});
}
/**
* This is the default constructor
*/
public SortingEx1() {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(520, 429);
this.setContentPane(getJContentPane());
this.setTitle("JFrame");
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(new BorderLayout());
jContentPane.add(getJPanel(), BorderLayout.NORTH);
jContentPane.add(getJPanel1(), BorderLayout.CENTER);
}
return jContentPane;
}
} // @jve:decl-index=0:visual-constraint="10,10"
'Study > Programming' 카테고리의 다른 글
자바 swing JTable 사용한 달력 (0) | 2009.05.21 |
---|---|
자바 Swing 구구단 (0) | 2009.05.21 |
AWT choice, list (0) | 2009.05.20 |
AWT 주민등록번호 검사 (0) | 2009.05.19 |
AWT (0) | 2009.05.18 |