import javax.swing.*;
import java.util.*;
import java.awt.*;
import javax.swing.border.*;
import java.awt.event.*;
class TagGenerator implements ActionListener
{
public TagGenerator(){} //만약을 위해 만든 생성자
JFrame frame;
JTextField urlField;
JTextField nameField;
JTextArea area;
public void actionPerformed(ActionEvent e){ //이벤트 처리
String str1 = urlField.getText();
String str2 = nameField.getText();
area.append("<a href = \"" + str1 + "\"> " + str2 + " </a>\n");
urlField.setText("");
nameField.setText("");
urlField.requestFocus();
}
public void view(){ //프레임 세팅
JFrame frame = new JFrame("A태그 생성기^^");
frame.add(input());
frame.setSize(1024, 768);
frame.setVisible(true);
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
Dimension f = frame.getSize();
frame.setLocation((int) (screen.getWidth() - f.getWidth()) / 2, (int) (screen.getHeight() - f.getHeight()) / 2);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Toolkit toolkit = Toolkit.getDefaultToolkit(); // 이미지 아이콘 바꾸기
Image img = toolkit.getImage("icon.gif");
frame.setIconImage(img);
}
JPanel input(){ //입력 모드
JPanel hapPannel = new JPanel();
JPanel upPannel = new JPanel();
JPanel upPannel1 = new JPanel();
JPanel upPannel2 = new JPanel();
JPanel downPannel = new JPanel();
JPanel savePannel = new JPanel();
hapPannel.setLayout(new BorderLayout());
upPannel.setLayout(new BorderLayout());
event();
event2();
upPannel1.add(urlField);
upPannel2.add(nameField);
upPannel.add(upPannel1,"North");
upPannel.add(upPannel2,"South");
area = new JTextArea();
area.setBorder(new LineBorder(new Color(179,179,179)));
area.setFont(new Font(null, Font.PLAIN, 15));
downPannel.add(area);
JScrollPane scroll = new JScrollPane(area);
int len= area.getText().length();
area.setCaretPosition(len); //자동 스크롤
downPannel.setBorder(new LineBorder(new Color(179,179,179)));
hapPannel.add(upPannel,"North");
hapPannel.add(downPannel,"Center");
hapPannel.add(savePannel, "South");
hapPannel.add(scroll);
return hapPannel;
}
void event(){
urlField = new JTextField();
urlField.setPreferredSize(new Dimension(1015, 40));
//urlField.addActionListener(this);
}
void event2(){
nameField = new JTextField();
nameField.setPreferredSize(new Dimension(1015, 40));
nameField.addActionListener(this);
}
public static void main(String[] args)
{
TagGenerator obj = new TagGenerator();
obj.view();
}
}
'JAVA' 카테고리의 다른 글
JDBC (0) | 2013.05.24 |
---|---|
입출력 스트림 (0) | 2013.05.21 |
자료구조 -알고리즘 (0) | 2013.05.10 |
숫자 100을 25%까지 난수로 찍는 간단한 코드 (0) | 2013.05.08 |
데드락 상황 만들기 & 해결 (0) | 2013.05.07 |