import java.awt.FileDialog;
import java.awt.Frame;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.MenuItem;
import java.awt.Panel;
import java.awt.GridBagLayout;
import java.awt.BorderLayout;
import java.awt.TextField;
import java.awt.Choice;
import java.awt.Rectangle;
import java.awt.Dimension;
import java.awt.List;
public class ChoiceEx2 extends Frame {
private static final long serialVersionUID = 1L;
private Panel panel = null;
private Panel panel1 = null;
private TextField textField = null;
private Choice choice = null;
private List list = null;
private MenuBar mb;
private Menu mFile;
private MenuItem miNew, miOpen, miSave, miSaveAS, miExit;
private Panel getPanel() {
if (panel == null) {
panel = new Panel();
panel.setLayout(new BorderLayout());
panel.add(getTextField(), BorderLayout.NORTH);
}
return panel;
}
private Panel getPanel1() {
if (panel1 == null) {
panel1 = new Panel();
panel1.setLayout(null);
panel1.add(getChoice(), null);
panel1.add(getList(), null);
}
return panel1;
}
private TextField getTextField() {
if (textField == null) {
textField = new TextField();
}
return textField;
}
private Choice getChoice() {
if (choice == null) {
choice = new Choice();
choice.setBounds(new Rectangle(18, 16, 102, 23));
choice.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent e) {
textField.setText(
choice.getSelectedIndex()
+ " : "
+ choice.getSelectedItem()
);
}
});
choice.add("2006");
choice.add("2007");
choice.add("2008");
choice.add("2009");
choice.add("2010");
choice.select(2);
}
return choice;
}
private List getList() {
if (list == null) {
list = new List();
list.setBounds(new Rectangle(203, 17, 120, 115));
list.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent e) {
textField.setText(
list.getSelectedIndex()
+ " : "
+ list.getSelectedItem()
);
}
});
list.add("일");
list.add("월");
list.add("화");
list.add("수");
list.add("목");
list.add("금");
list.add("토");
list.select(3);
}
return list;
}
public static void main(String[] args) {
ChoiceEx2 ce = new ChoiceEx2();
ce.setVisible(true);
}
public ChoiceEx2() {
super();
initialize();
}
private void initialize() {
this.setSize(350, 323);
this.setTitle("Frame");
mFile = new Menu("File");
miNew = new MenuItem("New");
miNew.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
textField.setText(miNew.getLabel());
}
});
miOpen = new MenuItem("Open");
miOpen.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
FileDialog fd = new FileDialog(ChoiceEx2.this, "파일 열기", FileDialog.LOAD);
fd.setDirectory("/home/whitefox"); //기본 설정 디렉토리
fd.setVisible(true);
if(fd.getDirectory() != null){
textField.setText(fd.getDirectory()+ " : " +fd.getFile());
}else{
textField.setText("");
}
textField.setText(fd.getDirectory() +" : " +fd.getFile());
}
});
miSave = new MenuItem("Save");
miSave.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
//textField.setText(miSave.getLabel());
FileDialog fd = new FileDialog(ChoiceEx2.this, "파일 저장", FileDialog.SAVE);
fd.setDirectory("/home/whitefox"); //기본 설정 디렉토리
fd.setVisible(true);
}
});
miSaveAS = new MenuItem("Save As ...");
miSaveAS.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
textField.setText(miSave.getLabel());
}
});
miExit = new MenuItem("Exit");
miExit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
System.exit(0);
}
});
mFile.add(miNew);
mFile.add(miOpen);
mFile.add(miSave);
mFile.add(miSaveAS);
mFile.addSeparator();
mFile.add(miExit);
mb = new MenuBar();
mb.add(mFile);
this.setMenuBar(mb);
this.add(getPanel(), BorderLayout.SOUTH);
this.add(getPanel1(), BorderLayout.CENTER);
this.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
}
}
import java.awt.Frame;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.MenuItem;
import java.awt.Panel;
import java.awt.GridBagLayout;
import java.awt.BorderLayout;
import java.awt.TextField;
import java.awt.Choice;
import java.awt.Rectangle;
import java.awt.Dimension;
import java.awt.List;
public class ChoiceEx2 extends Frame {
private static final long serialVersionUID = 1L;
private Panel panel = null;
private Panel panel1 = null;
private TextField textField = null;
private Choice choice = null;
private List list = null;
private MenuBar mb;
private Menu mFile;
private MenuItem miNew, miOpen, miSave, miSaveAS, miExit;
private Panel getPanel() {
if (panel == null) {
panel = new Panel();
panel.setLayout(new BorderLayout());
panel.add(getTextField(), BorderLayout.NORTH);
}
return panel;
}
private Panel getPanel1() {
if (panel1 == null) {
panel1 = new Panel();
panel1.setLayout(null);
panel1.add(getChoice(), null);
panel1.add(getList(), null);
}
return panel1;
}
private TextField getTextField() {
if (textField == null) {
textField = new TextField();
}
return textField;
}
private Choice getChoice() {
if (choice == null) {
choice = new Choice();
choice.setBounds(new Rectangle(18, 16, 102, 23));
choice.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent e) {
textField.setText(
choice.getSelectedIndex()
+ " : "
+ choice.getSelectedItem()
);
}
});
choice.add("2006");
choice.add("2007");
choice.add("2008");
choice.add("2009");
choice.add("2010");
choice.select(2);
}
return choice;
}
private List getList() {
if (list == null) {
list = new List();
list.setBounds(new Rectangle(203, 17, 120, 115));
list.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent e) {
textField.setText(
list.getSelectedIndex()
+ " : "
+ list.getSelectedItem()
);
}
});
list.add("일");
list.add("월");
list.add("화");
list.add("수");
list.add("목");
list.add("금");
list.add("토");
list.select(3);
}
return list;
}
public static void main(String[] args) {
ChoiceEx2 ce = new ChoiceEx2();
ce.setVisible(true);
}
public ChoiceEx2() {
super();
initialize();
}
private void initialize() {
this.setSize(350, 323);
this.setTitle("Frame");
mFile = new Menu("File");
miNew = new MenuItem("New");
miNew.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
textField.setText(miNew.getLabel());
}
});
miOpen = new MenuItem("Open");
miOpen.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
FileDialog fd = new FileDialog(ChoiceEx2.this, "파일 열기", FileDialog.LOAD);
fd.setDirectory("/home/whitefox"); //기본 설정 디렉토리
fd.setVisible(true);
if(fd.getDirectory() != null){
textField.setText(fd.getDirectory()+ " : " +fd.getFile());
}else{
textField.setText("");
}
textField.setText(fd.getDirectory() +" : " +fd.getFile());
}
});
miSave = new MenuItem("Save");
miSave.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
//textField.setText(miSave.getLabel());
FileDialog fd = new FileDialog(ChoiceEx2.this, "파일 저장", FileDialog.SAVE);
fd.setDirectory("/home/whitefox"); //기본 설정 디렉토리
fd.setVisible(true);
}
});
miSaveAS = new MenuItem("Save As ...");
miSaveAS.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
textField.setText(miSave.getLabel());
}
});
miExit = new MenuItem("Exit");
miExit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
System.exit(0);
}
});
mFile.add(miNew);
mFile.add(miOpen);
mFile.add(miSave);
mFile.add(miSaveAS);
mFile.addSeparator();
mFile.add(miExit);
mb = new MenuBar();
mb.add(mFile);
this.setMenuBar(mb);
this.add(getPanel(), BorderLayout.SOUTH);
this.add(getPanel1(), BorderLayout.CENTER);
this.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
}
}
'Study > Programming' 카테고리의 다른 글
자바 Swing 구구단 (0) | 2009.05.21 |
---|---|
자바 Swing (0) | 2009.05.21 |
AWT 주민등록번호 검사 (0) | 2009.05.19 |
AWT (0) | 2009.05.18 |
자바 달력 (0) | 2009.05.18 |