LogFrame.java
上传用户:kyckim
上传日期:2007-12-11
资源大小:332k
文件大小:2k
- package Pihatonttu;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- public class LogFrame extends JPanel {
- private DefaultListModel listModel = new DefaultListModel();
- private JFrame frame;
-
- LogFrame() {
- super(new BorderLayout());
-
- JList list = new JList(listModel);
- list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
- list.setSelectedIndex(0);
- JScrollPane listScrollPane = new JScrollPane(list);
- listScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
- listScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
- listScrollPane.setPreferredSize(new Dimension(600, 300));
- add(listScrollPane);
-
- JFrame.setDefaultLookAndFeelDecorated(true);
- frame = new JFrame("Pihatonttu Proxy");
- frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
- frame.setIconImage(PihatonttuMain.normalIcon.getImage());
- JComponent newContentPane = this;
- newContentPane.setOpaque(true);
- frame.setContentPane(newContentPane);
- frame.pack();
- }
-
- public void showLog() {
- if (frame.isVisible()){
- frame.toFront();
- return;
- }
- frame.setVisible(true);
- }
-
- public void addElement(final String element) {
- javax.swing.SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- listModel.addElement(element);
- }
- });
- }
-
- public void addElementFraction(final String element) {
- javax.swing.SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- listModel.removeElementAt(listModel.size()-1);
- listModel.addElement(element);
- }
- });
- }
-
- public void clear() {
- javax.swing.SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- listModel.clear();
- }
- });
- }
- }