> Kunne du ikke lige poste fejlene og et par linjer kode før og efter
> fejlene ?
> Ellers er det ret svært at sige, hvad der går galt.
at importere java.swing.text.* fjernede ca. 40% af fejlene, så nu er der kun
28 tilbage.
-------------- kode start -----------------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
import java.util; // der anvendes bla. ArrayList
public class Popstyle extends JFrame {
public static void main(String args[]) {
Popstyle window = new Popstyle();
window.setTitle("Popstyle");
window.setVisible(true);
}
public Popstyle() {
Container contentPane = getContentPane();
GridLayout layout = new GridLayout(0,1);
contentPane.setLayout(layout);
JTextPane textPane = new JTextPane();
contentPane.add(textPane);
// Herfra er blot indsat eksemplet fra
http://javaalmanac.com/egs/javax.swing.text/style_ListStyles2.html
// Makes text red
Style style = textPane.addStyle("Red", null);
StyleConstants.setForeground(style, Color.red);
// Inherits from "Red"; makes text red and underlined
style = textPane.addStyle("Red Underline", style);
StyleConstants.setUnderline(style, true);
// Makes text 24pts
style = textPane.addStyle("24pts", null);
StyleConstants.setFontSize(style, 24);
// Makes text 12pts
style = textPane.addStyle("12pts", null);
StyleConstants.setFontSize(style, 12);
// Makes text italicized
style = textPane.addStyle("Italics", null);
StyleConstants.setItalic(style, true);
// Makes text bold
style = textPane.addStyle("Bold", null);
StyleConstants.setBold(style, true);
JTextPane c = textPane;
// Construct a sorted list of style names
DefaultStyledDocument doc =
(DefaultStyledDocument)textPane.getDocument();
java.util.List l = new ArrayList();
Enumeration enum = doc.getStyleNames();
while (enum.hasMoreElements()) {
l.add(enum.nextElement());
}
Collections.sort(l);
// First sub menu applies character attributes
final JPopupMenu menu = new JPopupMenu();
JMenu submenu = new JMenu("Character");
for (int i=0; i<l.size(); i++) {
submenu.add(new JMenuItem(new DoStyleAction((String)l.get(i),
CHARACTER)));
}
menu.add(submenu);
// Second sub menu applies paragraph attributes
submenu = new JMenu("Paragraph");
for (int i=0; i<l.size(); i++) {
submenu.add(new JMenuItem(new DoStyleAction((String)l.get(i),
PARAGRAPH)));
}
menu.add(submenu);
// Third submenu applies logical attributes
submenu = new JMenu("Logical");
for (int i=0; i<l.size(); i++) {
submenu.add(new JMenuItem(new DoStyleAction((String)l.get(i),
LOGICAL)));
}
menu.add(submenu);
// Add a listener to display pop-up
textPane.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent evt) {
if (evt.isPopupTrigger()) {
menu.show(evt.getComponent(), evt.getX(), evt.getY());
}
}
public void mouseReleased(MouseEvent evt) {
if (evt.isPopupTrigger()) {
menu.show(evt.getComponent(), evt.getX(), evt.getY());
}
}
});
static final int CHARACTER = 1;
static final int PARAGRAPH = 2;
static final int LOGICAL = 3;
// Assumes the style name is the same as the action name.
// The type specifies how the style should be applied.
// The style is applied to the text within the selection.
public static class DoStyleAction extends
StyledEditorKit.StyledTextAction {
int type;
public DoStyleAction(String styleName, int type) {
super(styleName);
this.type = type;
}
public void actionPerformed(ActionEvent e) {
JTextPane c = (JTextPane)getEditor(e);
if (c != null) {
String styleName = e.getActionCommand();
StyledDocument doc = (StyledDocument)c.getDocument();
switch (type) {
case CHARACTER:
c.setCharacterAttributes(doc.getStyle(styleName), true);
break;
case PARAGRAPH:
c.setParagraphAttributes(doc.getStyle(styleName), true);
break;
case LOGICAL:
c.setLogicalStyle(doc.getStyle(styleName));
break;
}
}
}
}
}
}
-------------- kode slut -----------------
-------------- fejl start -----------------
[sti...]\popuptest\Popstyle.java:97: illegal start of expression
static final int CHARACTER = 1;
^
[sti...]\popuptest\Popstyle.java:98: illegal start of expression
static final int PARAGRAPH = 2;
^
[sti...]\popuptest\Popstyle.java:99: illegal start of expression
static final int LOGICAL = 3;
^
[sti...]\popuptest\Popstyle.java:104: illegal start of expression
public static class DoStyleAction extends
StyledEditorKit.StyledTextAction {
^
[sti...]\popuptest\Popstyle.java:104: ';' expected
public static class DoStyleAction extends
StyledEditorKit.StyledTextAction {
^
[sti...]\popuptest\Popstyle.java:5: cannot resolve symbol
symbol : class util
location: package java
import java.util; // der anvendes bla. ArrayList
^
[sti...]\popuptest\Popstyle.java:54: cannot resolve symbol
symbol : class ArrayList
location: class Popstyle
java.util.List l = new ArrayList();
^
[sti...]\popuptest\Popstyle.java:55: cannot resolve symbol
symbol : class Enumeration
location: class Popstyle
Enumeration enum = doc.getStyleNames();
^
[sti...]\popuptest\Popstyle.java:59: cannot resolve symbol
symbol : variable Collections
location: class Popstyle
Collections.sort(l);
^
..\DoStyleAction.java:33: 'class' or 'interface' expected
}
^
..\DoStyleAction.java:33: 'class' or 'interface' expected
}
^
..\DoStyleAction.java:6: modifier static not allowed here
public static class DoStyleAction extends StyledEditorKit.StyledTextAction {
^
..\DoStyleAction.java:6: package StyledEditorKit does not exist
public static class DoStyleAction extends StyledEditorKit.StyledTextAction {
^
..\DoStyleAction.java:12: cannot resolve symbol
symbol : class ActionEvent
location: class DoStyleAction
public void actionPerformed(ActionEvent e) {
^
[sti...]\popuptest\Popstyle.java:65: cannot resolve symbol
symbol : variable CHARACTER
location: class Popstyle
submenu.add(new JMenuItem(new DoStyleAction((String)l.get(i),
CHARACTER)));
^
[sti...]\popuptest\Popstyle.java:65: reference to JMenuItem is ambiguous,
both method JMenuItem(javax.swing.Icon) in javax.swing.JMenuItem and method
JMenuItem(javax.swing.Action) in javax.swing.JMenuItem match
submenu.add(new JMenuItem(new DoStyleAction((String)l.get(i),
CHARACTER)));
^
[sti...]\popuptest\Popstyle.java:72: cannot resolve symbol
symbol : variable PARAGRAPH
location: class Popstyle
submenu.add(new JMenuItem(new DoStyleAction((String)l.get(i),
PARAGRAPH)));
^
[sti...]\popuptest\Popstyle.java:72: reference to JMenuItem is ambiguous,
both method JMenuItem(javax.swing.Icon) in javax.swing.JMenuItem and method
JMenuItem(javax.swing.Action) in javax.swing.JMenuItem match
submenu.add(new JMenuItem(new DoStyleAction((String)l.get(i),
PARAGRAPH)));
^
[sti...]\popuptest\Popstyle.java:79: cannot resolve symbol
symbol : variable LOGICAL
location: class Popstyle
submenu.add(new JMenuItem(new DoStyleAction((String)l.get(i),
LOGICAL)));
^
[sti...]\popuptest\Popstyle.java:79: reference to JMenuItem is ambiguous,
both method JMenuItem(javax.swing.Icon) in javax.swing.JMenuItem and method
JMenuItem(javax.swing.Action) in javax.swing.JMenuItem match
submenu.add(new JMenuItem(new DoStyleAction((String)l.get(i),
LOGICAL)));
^
[sti...]\popuptest\Popstyle.java:117: cannot resolve symbol
symbol : variable CHARACTER
location: class DoStyleAction
case CHARACTER:
^
[sti...]\popuptest\Popstyle.java:120: cannot resolve symbol
symbol : variable PARAGRAPH
location: class DoStyleAction
case PARAGRAPH:
^
[sti...]\popuptest\Popstyle.java:123: cannot resolve symbol
symbol : variable LOGICAL
location: class DoStyleAction
case LOGICAL:
^
..\DoStyleAction.java:16: cannot resolve symbol
symbol : class StyledDocument
location: class DoStyleAction
StyledDocument doc = (StyledDocument)c.getDocument();
^
..\DoStyleAction.java:16: cannot resolve symbol
symbol : class StyledDocument
location: class DoStyleAction
StyledDocument doc = (StyledDocument)c.getDocument();
^
..\DoStyleAction.java:19: cannot resolve symbol
symbol : variable CHARACTER
location: class DoStyleAction
case CHARACTER:
^
..\DoStyleAction.java:22: cannot resolve symbol
symbol : variable PARAGRAPH
location: class DoStyleAction
case PARAGRAPH:
^
..\DoStyleAction.java:25: cannot resolve symbol
symbol : variable LOGICAL
location: class DoStyleAction
case LOGICAL:
^
28 errors
Tool completed with exit code 1
-------------- fejl slut -----------------