1.ϵͳ?系统林正英 源码???Դ??
ϵͳ????Դ??
import java.awt.*;/
*** @author Hardneedl
*/
interface Brush {
void doPaint(Graphics g);
}
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
/
*** @author Hardneedl
*/
final class StringPaintDemo extends JFrame {
public String getTitle() { return "String Paint";}
static private final Dimension size = new Dimension(, );
public Dimension getPreferredSize() { return size;}
public Dimension getMaximumSize() { return size;}
public Dimension getMinimumSize() { return size;}
public Dimension getSize() { return size;}
private String s;
private Brush stringBrush = new Brush() {
public void doPaint(Graphics g) {
Graphics gg = g.create();
gg.setColor(Color.RED);
gg.drawString(s == null ? "null" : s , , );
gg.dispose();
}
};
private JTextField txtField;
private JComponent canvas = new JComponent(){
protected void paintComponent(Graphics g) {
super.paintComponent(g);
stringBrush.doPaint(g);
}
};
private StringPaintDemo() throws HeadlessException {
init();
attachListeners();
doLay();
}
private void init() {
txtField = new JTextField();
}
private void attachListeners() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
txtField.getDocument().addDocumentListener(new DocumentListener(){
private void update(){
s = txtField.getText();
canvas.paintImmediately(canvas.getBounds());
}
public void changedUpdate(DocumentEvent e) { update();}
public void insertUpdate(DocumentEvent e) { update();}
public void removeUpdate(DocumentEvent e) { update();}
});
}
private void doLay() {
Container container = getContentPane();
container.add(txtField,BorderLayout.NORTH);
container.add(canvas, BorderLayout.CENTER);
pack();
setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new StringPaintDemo();
}
});
}
}