⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 styling.java

📁 learning java的源代码。书中每个实例都有相关的代码example。
💻 JAVA
字号:
//file: Styling.javaimport java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.text.*;public class Styling extends JFrame {  private JTextPane textPane;  public Styling(  ) {    super("Styling v1.0");    setSize(300, 200);    setLocation(200, 200);    textPane = new JTextPane(  );    textPane.setFont(new Font("Serif", Font.PLAIN, 24));    // create some handy attribute sets    SimpleAttributeSet red = new SimpleAttributeSet(  );    StyleConstants.setForeground(red, Color.red);    StyleConstants.setBold(red, true);    SimpleAttributeSet blue = new SimpleAttributeSet(  );    StyleConstants.setForeground(blue, Color.blue);    SimpleAttributeSet italic = new SimpleAttributeSet(  );    StyleConstants.setItalic(italic, true);    StyleConstants.setForeground(italic, Color.orange);    // add the text    append("In a ", null);    append("sky", blue);    append(" full of people\nOnly some want to ", null);    append("fly", italic);    append("\nIsn't that ", null);    append("crazy", red);    append("?", null);    Container content = getContentPane(  );    content.add(new JScrollPane(textPane), BorderLayout.CENTER);    setVisible(true);  }  protected void append(String s, AttributeSet attributes) {    Document d = textPane.getDocument(  );    try { d.insertString(d.getLength(  ), s, attributes); }    catch (BadLocationException ble) {}  }  public static void main(String[] args) {    JFrame f = new Styling(  );    f.addWindowListener(new WindowAdapter(  ) {      public void windowClosing(WindowEvent we) { System.exit(0); }    });    f.setVisible(true);  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -