private JMenuItem cut = new JMenuItem(\剪切 \); private JMenuItem paste = new JMenuItem(\粘贴 \); private JMenuItem selectAll = new JMenuItem(\全选 \); private JMenuItem delete = new JMenuItem(\删除 \); private Font font = new Font(\宋体\, 0, 12); public LTextField() { }
public LTextField(int column) { }
public LTextField(int column, String text) { }
public LTextField(String text) { }
public void focusGained(FocusEvent e) {
this.setText(text);
this.addFocusListener(this); this.addKeyListener(this);
this.setSelectionColor(new Color(0, 80, 140)); this.setSelectedTextColor(Color.white); this.addMouseListener(this); copy.setFont(font); cut.setFont(font); paste.setFont(font); selectAll.setFont(font); delete.setFont(font);
copy.addActionListener(this); cut.addActionListener(this); paste.addActionListener(this); selectAll.addActionListener(this); delete.addActionListener(this); popup.add(cut); popup.add(copy); popup.add(paste); popup.add(delete); popup.addSeparator(); popup.add(selectAll); this(text);
this.setColumns(column); this(column, \); this(\);
- 11 -
}
this.selectAll();
public void focusLost(FocusEvent e) { }
public void keyPressed(KeyEvent e) { }
public void keyReleased(KeyEvent e) { }
public void keyTyped(KeyEvent e) { }
public void actionPerformed(ActionEvent e) { }
public void mouseClicked(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON3) {
this.requestFocus();
if (this.getText().length() < 1) {
copy.setEnabled(false); cut.setEnabled(false); selectAll.setEnabled(false); delete.setEnabled(false); copy.setEnabled(true); cut.setEnabled(true); selectAll.setEnabled(true);
Object source = e.getSource(); if (source == cut)
this.cut(); this.copy(); this.paste(); this.selectAll();
this.replaceSelection(\); else if (source == copy) else if (source == paste) else if (source == selectAll) else if (source == delete)
if (e.getKeyCode() == KeyEvent.VK_ENTER) { }
this.transferFocus();
} else {
- 12 -
}
}
}
}
if (this.getSelectedText() != null)
delete.setEnabled(true); delete.setEnabled(false); else
popup.show(this, e.getX(), e.getY());
public void mouseEntered(MouseEvent e) { }
public void mouseExited(MouseEvent e) { }
public void mousePressed(MouseEvent e) { }
public void mouseReleased(MouseEvent e) { }
ProgressBar.java
package eb.cstop.swing;
import javax.swing.JLabel; import java.awt.*;
import java.awt.event.MouseListener; import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener; import java.util.ArrayList;
import java.awt.event.MouseWheelListener; import java.awt.event.MouseWheelEvent;
public class ProgressBar extends JLabel implements MouseListener,
MouseMotionListener, MouseWheelListener { private int value = 0; private int minLimit = 0; private int maxLimit = 100; private float alpha = 0.7f;
private Color border = new Color(0, 0, 0); private Color color = new Color(250, 160, 0); private ArrayList changeListener = new ArrayList(); private ProgressBarEvent event = new ProgressBarEvent();
- 13 -
public int getMaxLimit() {
public void setMaxLimit(int value) { }
if (value > 0)
maxLimit = value; maxLimit = 100; else
public int getMinLimt() { }
return minLimit;
public void setMinLimt(int value) { }
if (value > 0)
minLimit = value; minLimit = 0; else
public boolean removeProgressBarListener(ProgressBarListener listener) { }
return changeListener.remove(listener);
public void addProgressBarListener(ProgressBarListener listener) { }
changeListener.add(listener); public float getAlpha() { }
return alpha;
public void setAlpha(float alpha) { }
this.alpha = alpha; this.repaint(); public ProgressBar() { }
this.setPreferredSize(new Dimension(-1, 5)); this.addMouseListener(this); this.addMouseMotionListener(this); this.addMouseWheelListener(this);
- 14 -
}
return maxLimit;
public void setValueForChange(int value) { }
public void setValue(int value) { }
public int getValue() { }
public void setBorderColor(Color border) {
return value;
if (value == this.value)
return; return; return;
this.value = value; value = 0;
if (value < minLimit) else if (value > maxLimit) if (value >= minLimit) else
this.repaint();
ProgressBarListener listener = null; event.setValue(value);
event.setComparison((int) (((float) value / maxLimit) * 100.0f)); for (int i = 0; i < changeListener.size(); i++) { }
listener = (ProgressBarListener) changeListener.get(i); event.setSource(listener); listener.valueChanged(event); if (value == this.value)
return; return; return;
this.value = value; value = 0;
if (value < minLimit) else if (value > maxLimit) if (value >= minLimit) else
this.repaint();
- 15 -