Overriding redo method in drawing arrows

I have to undo and redo of path and arrows to them.at a time i need only either left arrow undo or right arrow undo depending on the direction in which path is drawn ie if its frm left to right then arrowhead left
and if its from right to left tthen arrowheadtright.
Undo is ok But problem comes with redo.Since if the last drawn path is from left to right then arrowright becomes null.pls suggest me a method overriding redo method for left and right arrows
private void redoButtonActionPerformed(java.awt.event.ActionEvent evt) {                                          
  try { m_edit.redo(); }
        catch (CannotRedoException cre)
        { cre.printStackTrace(); }
drawpanel.repaint();
undoButton.setEnabled(m_edit.canUndo());
redoButton.setEnabled(m_edit.canRedo());  
private void undoButtonActionPerformed(java.awt.event.ActionEvent evt) {                                          
        try { m_edit.undo(); }
         catch (CannotRedoException cre)
         { cre.printStackTrace(); }
         drawpanel.repaint();
         undoButton.setEnabled(m_edit.canUndo());
         redoButton.setEnabled(m_edit.canRedo());
class Edit extends AbstractUndoableEdit {
       protected Vector drawarc;
      protected Curve path;
      protected Vector vectlabel;
      protected drawlabel labelarc;
     protected Vector arrowheadleft;
     protected drawArrowHeads arrow1;
     protected Vector arrowheadright;
     protected  drawArrowHeadsecond arrow2;
       public Edit( Vector drawarc, Curve path ,Vector vectlabel,drawlabel labelarc,Vector arrowheadleft,drawArrowHeads arrow1,Vector arrowheadright,drawArrowHeadsecond arrow2)
          this.drawarc = drawarc;
          this.path = path;
                this.vectlabel=vectlabel;
                this.labelarc=labelarc;
                this.arrowheadleft=arrowheadleft;
                this.arrow1=arrow1;
                this.arrowheadright=arrowheadright;
                this.arrow2=arrow2;
     public void undo() throws CannotUndoException {
          drawarc.remove(path);
                vectlabel.remove(labelarc);
                arrowheadleft.remove(arrow1);
                arrowheadright.remove(arrow2);
     public void redo() throws CannotRedoException {
          drawarc.add( path);
                vectlabel.add(labelarc);
               // arrowheadleft.add(arrow1);
               // System.out.println("The arrowheadleft vector inside Edit method contains "+arrowheadleft.toString());
               arrowheadright.add(arrow2);
               System.out.println("The arrowheadright vector inside Edit method contains "+arrowheadright.toString());
         public boolean canUndo() {
          return true;
     public boolean canRedo() {
          return true;
     public String getPresentationName() {
          return "Add Arc";
m_edit=new Edit(drawarc, path , vectlabel, labelarc, arrowheadleft, arrow1, arrowheadright, arrow2);
undoButton.setText(m_edit.getUndoPresentationName());
redoButton.setText(m_edit.getRedoPresentationName());
undoButton.setEnabled(m_edit.canUndo());
redoButton.setEnabled(m_edit.canRedo());

..arrowright becomes null..Check for null value. If null, then do nothing with it.

Similar Messages

  • Override scrollpane methods?

    problem: I create a time series line graph in a buffered image that has a variable width, sometimes the width is in the millions of pixels and the resulting buffered image is too large to fit into memory, even if I increase the available memory with the -Xmx1024m option. I then place the a fore mentioned buffered image into a scrollpane for viewing.
    I would like to draw only the portion of the graph that is viewable and override the scrollpane methods to redraw the image based on an x position over the total width, but I haven't found anything in the API on overriding the scrollbar or the arrow buttons. Has anyone tried this, or seen and example of how to do it?
    I am aware of products such as JFreeChart and PtolemyPlot, however I don't think either is a good fit for the project and I don't have any use for their capabilities. I am open to any other suggestions on how to accomplish this goal.
    Thanks,
    Peter

    You can try to use JScrollPane by placing a custom component extending JComponent inside the scroll pane and setting it's preferred size to the required size.
    Override paintComponent method of this component and get the view rectangle from the viewport and paint only the visible area.
    If this doesn't work you might need to use JScrollBar and write the logic yourself in this case.

  • How to draw arrows?

    This code plots a simple XYLine Chart
    import javafx.application.Application;
    import javafx.event.EventHandler;
    import javafx.scene.Scene;
    import javafx.scene.chart.CategoryAxis;
    import javafx.scene.chart.LineChart;
    import javafx.scene.chart.NumberAxis;
    import javafx.scene.chart.XYChart;
    import javafx.scene.input.MouseEvent;
    import javafx.scene.layout.BorderPane;
    import javafx.stage.Stage;
    public class XyChart extends Application {
        @Override
        public void start(Stage stage) {
           stage.setTitle("Line plot");
           final CategoryAxis xAxis = new CategoryAxis();
           final NumberAxis yAxis = new NumberAxis(1, 21,0.1);
           yAxis.setTickUnit(1);
           yAxis.setPrefWidth(35);
           yAxis.setMinorTickCount(10);
           yAxis.setTickLabelFormatter(new NumberAxis.DefaultFormatter(yAxis){
                @Override
            public String toString(Number object){
                    String label;
                    label = String.format("%7.2f", object.floatValue());
                    return label;
    final LineChart<String, Number>lineChart = new LineChart<String, Number>(xAxis, yAxis);
           lineChart.setCreateSymbols(false);
           lineChart.setAlternativeRowFillVisible(false);
           lineChart.setLegendVisible(false);
           XYChart.Series series1 = new XYChart.Series();
            series1.getData().add(new XYChart.Data("Jan", 1));
            series1.getData().add(new XYChart.Data("Feb", 4));
            series1.getData().add(new XYChart.Data("Mar", 2.5));
            series1.getData().add(new XYChart.Data("Apr", 5));
            series1.getData().add(new XYChart.Data("May", 6));
            series1.getData().add(new XYChart.Data("Jun", 8));
            series1.getData().add(new XYChart.Data("Jul", 12));
            series1.getData().add(new XYChart.Data("Aug", 8));
            series1.getData().add(new XYChart.Data("Sep", 11));
            series1.getData().add(new XYChart.Data("Oct", 13));
            series1.getData().add(new XYChart.Data("Nov", 10));
            series1.getData().add(new XYChart.Data("Dec", 20));
            BorderPane pane = new BorderPane();
            pane.setCenter(lineChart);         
            Scene scene = new Scene(pane, 800, 600);
            lineChart.setAnimated(false);
            lineChart.getData().addAll(series1);      
            stage.setScene(scene);
            stage.show();
        public static void main(String[] args) {
            launch(args);
    }I would like to draw arrows on the chart by left mouse click pressed and moved,such as this example
    [http://s8.postimage.org/5xgu0j6kl/A02480.png]
    how to do this?
    Thanks!
    Edited by: 932518 on 6-nov-2012 4.32

    Hi. It is possible to draw arrows on a chart. Please try the modified example:
    import javafx.application.Application;
    import javafx.event.EventHandler;
    import javafx.scene.Group;
    import javafx.scene.Scene;
    import javafx.scene.chart.CategoryAxis;
    import javafx.scene.chart.LineChart;
    import javafx.scene.chart.NumberAxis;
    import javafx.scene.chart.XYChart;
    import javafx.scene.control.Label;
    import javafx.scene.input.MouseEvent;
    import javafx.scene.layout.BorderPane;
    import javafx.scene.paint.Color;
    import javafx.scene.shape.LineTo;
    import javafx.scene.shape.MoveTo;
    import javafx.scene.shape.Path;
    import javafx.scene.shape.Polygon;
    import javafx.stage.Stage;
    public class XyChart extends Application {
         Path path;
         BorderPane pane = new BorderPane();
        double startx = 0;
        double starty = 0;
        double endx = 0;
        double endy = 0;
        public static void main(String[] args) {
            launch(args);
        @Override
        public void start(Stage stage) {
            final CategoryAxis xAxis = new CategoryAxis();
            final NumberAxis yAxis = new NumberAxis(1, 21, 0.1);
            yAxis.setTickUnit(1);
            yAxis.setPrefWidth(35);
            yAxis.setMinorTickCount(10);
            yAxis.setTickLabelFormatter(new NumberAxis.DefaultFormatter(yAxis) {
                @Override
                public String toString(Number object) {
                    String label;
                    label = String.format("%7.2f", object.floatValue());
                    return label;
            final LineChart<String, Number> lineChart = new LineChart<String, Number>(xAxis, yAxis);
            lineChart.setCreateSymbols(false);
            lineChart.setAlternativeRowFillVisible(false);
            lineChart.setLegendVisible(false);
            XYChart.Series series1 = new XYChart.Series();
            series1.getData().add(new XYChart.Data("Jan", 1));
            series1.getData().add(new XYChart.Data("Feb", 4));
            series1.getData().add(new XYChart.Data("Mar", 2.5));
            series1.getData().add(new XYChart.Data("Apr", 5));
            series1.getData().add(new XYChart.Data("May", 6));
            series1.getData().add(new XYChart.Data("Jun", 8));
            series1.getData().add(new XYChart.Data("Jul", 12));
            series1.getData().add(new XYChart.Data("Aug", 8));
            series1.getData().add(new XYChart.Data("Sep", 11));
            series1.getData().add(new XYChart.Data("Oct", 13));
            series1.getData().add(new XYChart.Data("Nov", 10));
            series1.getData().add(new XYChart.Data("Dec", 20));
            pane.setCenter(lineChart);
            Scene scene = new Scene(pane, 800, 600);
            lineChart.setAnimated(false);
            lineChart.getData().addAll(series1);
             path = new Path();
              path.setStrokeWidth(1);
            path.setStroke(Color.BLACK);
            scene.setOnMouseReleased(mHandler);
            scene.setOnMousePressed(mHandler);
            pane.getChildren().add(path);
            stage.setScene(scene);
            stage.show();
        EventHandler<MouseEvent> mHandler = new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent me) {
                if (me.getEventType() == MouseEvent.MOUSE_PRESSED) {
                    startx = me.getX();
                    starty = me.getY();
                    path.getElements().add(new MoveTo(startx, starty));
                } else if (me.getEventType() == MouseEvent.MOUSE_RELEASED) {
                    endx = me.getX();
                    endy = me.getY();
                    path.getElements().add(new LineTo(endx, endy));
                    Polygon arrow = new Polygon();
                    arrow.getPoints().addAll(new Double[]{
                                0.0, 5.0,
                                -5.0, -5.0,
                                5.0, -5.0});
                    double angle = Math.atan2(endy - starty, endx - startx) * 180 / 3.14;
                    arrow.setRotate((angle - 90));
                    arrow.setTranslateX(startx);
                    arrow.setTranslateY(starty);
                    arrow.setTranslateX(endx);
                    arrow.setTranslateY(endy);
                    pane.getChildren().add(arrow);
    }

  • How to use paint method to draw in many componets.

    Hi!
    I have code like this:
    public class MainPanel extends JPanel{
       JPanel p1;
       JPanel p2;
       public MainPanel(){
           super(new BorderLayout());
           p1 = new JPanel();
           p2 = new JPanel();
           add(p1 , BorderLayout.Center);
           add(p2 , BorderLayout. West);
           setVisible(true);
    @Override
        protected void paintComponent(Graphics g) {
           g.setColor(Color.red);
           g.fillrect(10,10,10,10);
    }This code is onle an example. Supose, this code will paint black rectangle on "main panel" to which p1 and p2 are added. What should i do to be able to paint this rectangle on p1 or p2 without creating separate classes in which i will override paintComponents() method for p1 and p2. I would like to avoid creating separete classes for each panels. Is there any way to do that using one paint Components method. Thanks in advance for all respone.

    (where's Darryl when you need him?)Erm, Pete, since when did I become an expert lol?
    Lost my hard disk, its been hiccuping for a couple of weeks now. I'm running on an old 20 GB PATA with a 5GB c drive. No IDE, no offline Javadoc. I'll get a HDD in the morning, but I hope I can spin up the old disk at least once and recover the last week's "work" ... just fun stuff actually.
    Why does this code draw rectangles just for split second?repaint() (and consequently paint(), paintComponent() and other painting methods) may be called by the system any time it is detected that the component needs to be repainted. Since you do not have a override for paintComponent, it will perform its default painting and paint the entire component, wiping out your rectangle.
    For persistent drawing on a JPanel or JComponent I know only one way: override paintComponent. If you need to avoid this, you could go with morgalr's suggestion to use JLabel.
    For this you would draw the triangle/rectangle/whatever to a BufferedImage, then call label.setIcon with a new ImageIcon constructed from the BufferedImage.
    Also, avoid obtaining a Graphics reference via getGraphics. During the lifetime of a visible component, various different Graphics references may be passed into the paintComponent method, so the reference you obtain may not be current. getGraphics can also return null.
    luck, db

  • Is not abstract and does not override abstract method actionPerformed

    I dont how to corr. Please help!! and thank you very much!!
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class test extends JFrame implements ActionListener, ItemListener
              private CenterPanel centerPanel;
              private QuestionPanel questionPanel;
              private ButtonPanel buttonPanel;
              private ResponsePanel responsePanel;
              private JButton b1,b2,b3,b4,b5;               //Create five references to Jbutton instances
         private JTextField t1,t2,t3,t4,t5;          //Create five references to JTextField instances
              private JLabel label1;                    //Create one references to JLabel instances
              private JRadioButton q1,q2,q3;               //Create three references to JRadioButton instances
              private ButtonGroup radioGroup;               //Create one references to Button Group instances
              private int que1[] = new int[5];           //Create int[4] Array
              private int que2[] = new int[5];
              private int que3[] = new int[5];
              private String temp1, temp2, temp3, temp4, temp5, temp6, temp7, temp8, temp9, temp10,
                        temp11, temp12, temp13, temp14, temp15;
    public test (String header)
              super(header);
              Container container = getContentPane();
              label1 = new JLabel ("PLease click on your response to ");     
              q1 = new JRadioButton("I understand most of the content of this subject",true);
              add(q1);
              q2 = new JRadioButton("I see the relevance of the subject to my degree",false);
              add(q2);
              q3 = new JRadioButton("The workload in this subject is appropriate",false);
              add(q3);
              radioGroup = new ButtonGroup();               //JRadioButton belong to ButtonGroup
              radioGroup.add(q1);
              radioGroup.add(q2);
              radioGroup.add(q3);
              JPanel buttonPanel = new JPanel();
              JPanel responsePanel = new JPanel();
              JPanel questionPanel = new JPanel();
              JPanel centerPanel = new JPanel();
              b1 = new JButton ("Strongly DISAGREE");          //Instantiate JButton with text
              b1.addActionListener (this);               //Register JButtons to receive events
              b2 = new JButton ("DISAGREE");
              b2.addActionListener (this);
              b3 = new JButton ("Neither AGREE or DISAGREE");
              b3.addActionListener (this);
              b4 = new JButton ("AGREE");
              b4.addActionListener (this);
              b5 = new JButton ("Strongly AGREE");
              b5.addActionListener (this);
              buttonPanel.setLayout(new GridLayout(5,1));
              buttonPanel.add(b1);
              buttonPanel.add(b2);
              buttonPanel.add(b3);
              buttonPanel.add(b4);
              buttonPanel.add(b5);
              t1 = new JTextField ("0",3);               //JTextField contains empty string
              t2 = new JTextField ("0",3);
              t3 = new JTextField ("0",3);
              t4 = new JTextField ("0",3);
              t5 = new JTextField ("0",3);
              t1.setEditable( false );
              t2.setEditable( false );
              t3.setEditable( false );
              t4.setEditable( false );
              t5.setEditable( false );
              responsePanel.setLayout(new GridLayout(5,1));
              responsePanel.add(t1);
              responsePanel.add(t2);
              responsePanel.add(t3);
              responsePanel.add(t4);
              responsePanel.add(t5);
              questionPanel.setLayout(new GridLayout(4,1));
              questionPanel.add(label1);
              questionPanel.add(q1);
              questionPanel.add(q2);
              questionPanel.add(q3);
              centerPanel.add(buttonPanel,BorderLayout.CENTER);
              centerPanel.add(responsePanel,BorderLayout.EAST);
              container.add(centerPanel,BorderLayout.WEST);
              container.add(questionPanel,BorderLayout.NORTH);
              q1.addActionListener(
                   new ActionListener(){
              public void actionPerformed( ActionEvent e )          
    {                                        //actionPerformed of all registered listeners
              if (e.getSource() == b1) {
                   que1[0] = Integer.parseInt(t1.getText()) + 1;
                   String temp1 = String.valueOf(que1[0]);
              t1.setText(temp1);
              else if (e.getSource() == b2)     {
                   que1[1] = Integer.parseInt(t2.getText()) + 1;
                   String temp2 = String.valueOf(que1[1]);
              t2.setText(temp2);
              else if (e.getSource() == b3)     {
                   que1[2] = Integer.parseInt(t3.getText()) + 1;
                   String temp3 = String.valueOf(que1[2]);
              t3.setText(temp3);
              else if (e.getSource() == b4)     {
                   que1[3] = Integer.parseInt(t4.getText()) + 1;
                   String temp4 = String.valueOf(que1[3]);
              t4.setText(temp4);
              else if (e.getSource() == b5)     {
                   que1[4] = Integer.parseInt(t5.getText()) + 1;
                   String temp5 = String.valueOf(que1[4]);
              t5.setText(temp5);
    } //end action performed
              q2.addActionListener(
                   new ActionListener(){
              public void actionPerformed( ActionEvent e )          
    {                                        //actionPerformed of all registered listeners
              if (e.getSource() == b1) {
                   que2[0] = Integer.parseInt(t1.getText()) + 1;
                   String temp6 = String.valueOf(que2[0]);
              t1.setText(temp1);
              else if (e.getSource() == b2)     {
                   que2[1] = Integer.parseInt(t2.getText()) + 1;
                   String temp7 = String.valueOf(que2[1]);
              t2.setText(temp7);
              else if (e.getSource() == b3)     {
                   que2[2] = Integer.parseInt(t3.getText()) + 1;
                   String temp8 = String.valueOf(que2[2]);
              t3.setText(temp8);
              else if (e.getSource() == b4)     {
                   que2[3] = Integer.parseInt(t4.getText()) + 1;
                   String temp9 = String.valueOf(que2[3]);
              t4.setText(temp9);
              else if (e.getSource() == b5)     {
                   que2[4] = Integer.parseInt(t5.getText()) + 1;
                   String temp10 = String.valueOf(que2[4]);
              t5.setText(temp10);
    } //end action performed
              q3.addActionListener(
                   new ActionListener(){
              public void actionPerformed( ActionEvent e )          
    {                                        //actionPerformed of all registered listeners
              if (e.getSource() == b1) {
                   que3[0] = Integer.parseInt(t1.getText()) + 1;
                   String temp11 = String.valueOf(que3[0]);
              t1.setText(temp11);
              else if (e.getSource() == b2)     {
                   que3[1] = Integer.parseInt(t2.getText()) + 1;
                   String temp12 = String.valueOf(que3[1]);
              t2.setText(temp12);
              else if (e.getSource() == b3)     {
                   que3[2] = Integer.parseInt(t3.getText()) + 1;
                   String temp13 = String.valueOf(que3[2]);
              t3.setText(temp13);
              else if (e.getSource() == b4)     {
                   que3[3] = Integer.parseInt(t4.getText()) + 1;
                   String temp14 = String.valueOf(que3[3]);
              t4.setText(temp14);
              else if (e.getSource() == b5)     {
                   que3[4] = Integer.parseInt(t5.getText()) + 1;
                   String temp15 = String.valueOf(que3[4]);
              t5.setText(temp15);
    } //end action performed
    }//end constructor test
    public void itemStateChanged(ItemEvent item) {
    //int state = item.getStateChange();
    //if (q1 == item.SELECTED)
              public class ButtonPanel extends JPanel
                   public ButtonPanel()
              public class CenterPanel extends JPanel
                   public CenterPanel()
              public class QuestionPanel extends JPanel
                   public QuestionPanel()
              public class ResponsePanel extends JPanel
                   public ResponsePanel()
    public static void main(String [] args)
         test surveyFrame = new test("Student Survey") ;
         surveyFrame.setSize( 500,300 );
         surveyFrame.setVisible(true);
         surveyFrame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
         }//end main
    }//end class test

    is not abstract and does not override abstract method actionPerformed
    Oh, I see that the title of your post is an error message? Ok. Well, the test class is declared as implementing an ActionListener. That means the test class must have an actionPerformed() method. Your test class apparently does not.
    It does not appear that the test class needs to implement ActionListener. You are using annonymous classes as listeners.

  • Is not abstract and does not override abstract method tablechanged

    I will remove all the gui code to make it shorter, but my problem lies with my InteractiveTableModelListener.
    public class Meet extends JPanel{
      private static void createAndShowGUI() {
            JFrame frame = new JFrame("MEET_dataTable");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.add(new Meet(), BorderLayout.CENTER);
            frame.pack();
            frame.setVisible(true);
    public class InteractiveTableModelListener implements TableModelListener {
         public void TableChanged(TableModelEvent evt) {
      if (evt.getType() == TableModelEvent.UPDATE) {
          int column = evt.getColumn();
          int row = evt.getFirstRow();
          dataTable.setColumnSelectionInterval(column + 1, column + 1);
          dataTable.setRowSelectionInterval(row, row);
    class InteractiveRenderer extends DefaultTableCellRenderer {
      protected int interactiveColumn;
      public InteractiveRenderer(int interactiveColumn) {
          this.interactiveColumn = interactiveColumn;
    public Component getTableCellRendererComponent(JTable dataTable,
         Object value, boolean isSelected, boolean hasFocus, int row,
         int column)
      Component c = super.getTableCellRendererComponent(dataTable, value, isSelected, hasFocus, row, column);
       if (column == interactiveColumn && hasFocus) {
         if ((Meet.this.tableModel.getRowCount() - 1) == row &&
            !Meet.this.tableModel.hasEmptyRow())
             Meet.this.tableModel.addEmptyRow();
        highlightLastRow(row);
      return c;
    public void highlightLastRow(int row) {
         int lastrow = tableModel.getRowCount();
      if (row == lastrow - 1) {
          dataTable.setRowSelectionInterval(lastrow - 1, lastrow - 1);
      else {
          dataTable.setRowSelectionInterval(row + 1, row + 1);
         dataTable.setColumnSelectionInterval(0, 0);
    public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                UIManager.put("swing.boldMetal", Boolean.FALSE);
                createAndShowGUI();
    }As i say, i have removed all the gui code to make it shorter, but in this code i create the table and add all the model to it. I am being returned with the error
    Meet.InteractiveTableModelListener is not abstract and does not override abstract method tableChanged(javax.swing.event.TableModelEvent)in javax.swing.event.TableModelListener
    what would be causing this error?
    Cheers

    Sorry, just figured out my silly error, the method is tableChanged not TableChanged.
    cheers
    TOPIC CLOSED
    Edited by: nick2price on Sep 11, 2008 7:08 AM

  • Is not abstract and does not override abstract method ERROR

    Hello. I'm new at all this, and am attempting to recreate a sample code out of my book (Teach Yourself XML in 24 Hours), and I keep getting an error. I appriciate any help.
    This is the Error that I get:
    DocumentPrinter is not abstract and does not override abstract method skippedEntity(java.lang.String) in org.xml.sax.ContentHandler
    public class DocumentPrinter implements  ContentHandler, ErrorHandler
            ^This is the sourcecode:
    import org.xml.sax.Attributes;
    import org.xml.sax.ContentHandler;
    import org.xml.sax.ErrorHandler;
    import org.xml.sax.Locator;
    import org.xml.sax.SAXParseException;
    import org.xml.sax.XMLReader;
    public class DocumentPrinter implements  ContentHandler, ErrorHandler
    // A Constant containing the name of the SAX parser to use.
    private static final String PARSER_NAME = "org.apache.xerces.parsers.SAXParser";
    public static void main(String[] args)
       // Check to see whether the user supplied any command line arguments.  If not, print an error and exit.
       if (args.length == 0)
         System.out.println("No XML document path specified.");
         System.exit(1);
       // Create a new instance of the DocumentPrinter class.
       DocumentPrinter dp = new DocumentPrinter();
       try
         // Create a new instance of the XML Parser.
         XMLReader parser = (XMLReader)Class.forName(PARSER_NAME).newInstance();
         // Set the parser's content handler
        // parser.setContentHandler(dp);
         // Set the parsers error handler
         parser.setErrorHandler(dp);
         // Parse the file named in the argument
         parser.parse(args[0]);
       catch (Exception ex)
         System.out.println(ex.getMessage());
         ex.printStackTrace();
    public void characters(char[] ch, int start, int length)
       String chars ="";
       for (int i = start; i < start + length; i++)
         chars = chars + ch;
    System.out.println("Recieved characters: " + chars);
    public void startDocument()
    System.out.println("Start Document.");
    public void endDocument()
    System.out.println("End of Document.");
    public void startElement(String namespaceURI, String localName, String qName, Attributes atts)
    System.out.println("Start element: " + localName);
    for (int i = 0; i < atts.getLength(); i++)
    System.out.println(" Attribute: " + atts.getLocalName(i));
    System.out.println(" Value: " + atts.getValue(i));
    public void endElement(String namespaceURI, String localName, String qName)
    System.out.println("End of element: " + localName);
    public void startPrefixMapping(String prefix, String uri)
    System.out.println("Prefix mapping: " + prefix);
    System.out.println("URI: " + uri);
    public void endPrefixMapping(String prefix)
    System.out.println("End of prefix mapping: " + prefix);
    public void ignorableWhitespace(char[] ch, int start, int length)
    System.out.println("Recieved whitespace.");
    public void processingInstruction(String target, String data)
    System.out.println("Recieved processing instruction:");
    System.out.println("Target: " + target);
    System.out.println("Data: " + data);
    public void setDocumentLocation(Locator locator)
    // Nada
    public void error(SAXParseException exception)
    System.out.println("Parsing error on line " + exception.getLineNumber());
    public void fatalError(SAXParseException exception)
    System.out.println("Fatal parsing error on line " + exception.getLineNumber());
    public void warning(SAXParseException exception)
    System.out.println("Warning on line " + exception.getLineNumber());

    Check to make sure that the arguments are consistent with your ContentHandler class. Probably the wrong type.
    I think you forgot to include the skippedEntity method, it seems to be missing. Even if an implemented class has a method that you are not using, you still have to include the method in your code even if it doesn't do anything.
    Message was edited by:
    ChargersTule1

  • ...is not abstract and does not override abstract method compare

    Why am I getting the above compile error when I am very clearly overriding abstract method compare (ditto abstract method compareTo)? Here is my code -- which was presented 1.5 code and I'm trying to retrofit to 1.4 -- followed by the complete compile time error. Thanks in advance for your help (even though I'm sure this is an easy question for you experts):
    import java.util.*;
       This program sorts a set of item by comparing
       their descriptions.
    public class TreeSetTest
       public static void main(String[] args)
          SortedSet parts = new TreeSet();
          parts.add(new Item("Toaster", 1234));
          parts.add(new Item("Widget", 4562));
          parts.add(new Item("Modem", 9912));
          System.out.println(parts);
          SortedSet sortByDescription = new TreeSet(new
             Comparator()
                public int compare(Item a, Item b)   // LINE CAUSING THE ERROR
                   String descrA = a.getDescription();
                   String descrB = b.getDescription();
                   return descrA.compareTo(descrB);
          sortByDescription.addAll(parts);
          System.out.println(sortByDescription);
       An item with a description and a part number.
    class Item implements Comparable     
          Constructs an item.
          @param aDescription the item's description
          @param aPartNumber the item's part number
       public Item(String aDescription, int aPartNumber)
          description = aDescription;
          partNumber = aPartNumber;
          Gets the description of this item.
          @return the description
       public String getDescription()
          return description;
       public String toString()
          return "[descripion=" + description
             + ", partNumber=" + partNumber + "]";
       public boolean equals(Object otherObject)
          if (this == otherObject) return true;
          if (otherObject == null) return false;
          if (getClass() != otherObject.getClass()) return false;
          Item other = (Item) otherObject;
          return description.equals(other.description)
             && partNumber == other.partNumber;
       public int hashCode()
          return 13 * description.hashCode() + 17 * partNumber;
       public int compareTo(Item other)   // OTHER LINE CAUSING THE ERROR
          return partNumber - other.partNumber;
       private String description;
       private int partNumber;
    }Compiler error:
    TreeSetTest.java:25: <anonymous TreeSetTest$1> is not abstract and does not over
    ride abstract method compare(java.lang.Object,java.lang.Object) in java.util.Com
    parator
                public int compare(Item a, Item b)
                           ^
    TreeSetTest.java:41: Item is not abstract and does not override abstract method
    compareTo(java.lang.Object) in java.lang.Comparable
    class Item implements Comparable
    ^
    2 errors

    According to the book I'm reading, if you merely take
    out the generic from the code, it should compile and
    run in v1.4 (assuming, of course, that the class
    exists in 1.4). I don't know what book you are reading but that's certainly incorrect or incomplete at least. I've manually retrofitted code to 1.4, and you'll be inserting casts as well as replacing type references with Object (or the erased type, to be more precise).
    These interfaces do exist in 1.4, and
    without the generics.Exactly. Which means compareTo takes an Object, and you should change your overriding method accordingly.
    But this raises a new question: how does my 1.4
    compiler know anything about generics? It doesn't and it can't. As the compiler is telling you, those interfaces expect Object. Think about it, you want to implement one interface which declares a method argument type of Object, in several classes, each with a different type. Obviously all of those are not valid overrides.

  • Product is not abstract and does not override abstract method

    Received the following errors.
    Product.java:3: Product is not abstract and does not override abstract method ge
    tDisplayText() in Displayable
    public class Product implements Displayable
    ^
    Product.java:16: getDisplayText() in Product cannot implement getDisplayText() i
    n Displayable; attempting to use incompatible return type
    found : void
    required: java.lang.String
    public void getDisplayText()
    ^
    2 errors
    Code reads as follows
    import java.text.NumberFormat;
    public class Product implements Displayable
         private String code;
         private String description;
         private double price;
         public Product()
              this.code = "";
              this.description = "";
              this.price = 0;
    public void getDisplayText()
    String message =
    "Code: " + code + "\n" +
    "Description: " + description + "\n" +
    "Price: " + this.getFormattedPrice() + "\n";
         public Product(String code, String description, double price)
              this.code = code;
              this.description = description;
              this.price = price;
         public void setCode(String code)
              this.code = code;
         public String getCode(){
              return code;
         public void setDescription(String description)
              this.description = description;
         public String getDescription()
              return description;
         public void setPrice(double price)
              this.price = price;
         public double getPrice()
              return price;
         public String getFormattedPrice()
              NumberFormat currency = NumberFormat.getCurrencyInstance();
              return currency.format(price);
    Please help!

    Received the following errors.
    Product.java:3: Product is not abstract and does not
    override abstract method ge
    tDisplayText() in Displayable
    public class Product implements Displayable
    ^
    Product.java:16: getDisplayText() in Product cannot
    implement getDisplayText() i
    n Displayable; attempting to use incompatible return
    type
    found : void
    required: java.lang.String
    public void getDisplayText()
    ^
    2 errors
    Code reads as follows
    Please use the code tags when posting code. There is a code button right above the text box where you enter your post. Click on it and put the code between the code tags.
    These error messages are quite clear in telling what is wrong. You have an Interface called Displayable that specifies a method something like thispublic String getDisplayText() {But in your Product source code, you created thismethodpublic void getDisplayText() {The compiler is complaining because the methods are not the same.
    You also need to return a String in the method probalby like thisreturn message;

  • Overriding a method in abap

    In Java it is simple to extend a class and override a method - the whole idea of polymorphism. In abap, I'm attempting to do the same, but don't know quite how. I've created as a demo a zclass and made a sap standard class its superclass in properties. How do I override a protected method from here?

    Marcin says:
    Unfortunatelly overriding is not possible in ABAP, only redefinition is allowed. The method singature must stay the same in all subsequent classes.
    I guess,
    Overriding - Redefinition of the implementation of inherited method. This is possible by addition REDEFINITION to the method.
    Overloading - Changing the method parameters of inherited method
    Regards,
    Naimesh Patel

  • I want to know how to draw arrows & dashed lines in a picture control

    I have to draw arrows & dashed lines in a picture control. Just like we can do that in word or paint etc. I need to do the same using the mouse and drag the line/arrow till I realease the mouse. I am able to this for a normal line ( it works perfectly) but when I have to draw an arrow or a line I am stumped.

    Unfortunately, you have to code your own VIs to do these. It's not going to be too complicated if you manage the animation (while dragging the mouse) with a normal line and draw the dashed line/arrow at the end (when releasing the mouse button).
    In both cases, you'll know start/end line coordinates, thus having the line equation. For arrows, you need to calculate the angle in order to draw it properly.
    A simpler solution may be an activeX control with these features (Paint like) already integrated or to develop one in Visual Basic (at least it will be simpler to manage mouse events and drawing tasks).
    Let's hope somebody already did it and wants to share.

  • How to override a method in an inner class of the super class

    I have a rather horribly written class, which I need to adapt. I could simply do this if I could override a method in one of it's inner classes. My plan then was to extend the original class, and override the method in question. But here I am struggling.
    The code below is representative of my situation.
    public class ClassA
       ValueChecks vc = null;
       /** Creates a new instance of Main */
       public ClassA()
          System.out.println("ClassA Constructor");
          vc = new ValueChecks();
          vc.checkMaximum();
         // I want this to call the overridden method, but it does not, it seems to call
         // the method in this class. probably because vc belongs to this class
          this.vc.checkMinimum();
          this.myMethod();
       protected void myMethod()
          System.out.println("myMethod(SUPER)");
       protected class ValueChecks
          protected boolean checkMinimum()
             System.out.println("ValueChecks.checkMinimum (SUPER)");
             return true;
          protected boolean checkMaximum()
             return false;
    }I have extended ClassA, call it ClassASub, and it is this Class which I instantiate. The constructor in ClassASub obviously calls the constructor in ClassA. I want to override the checkMinimum() method in ValueChecks, but the above code always calls the method in ClassA. The ClassASub code looks like this
    public class ClassASub extends ClassA
       public ClassAInner cias;
       /** Creates a new instance of Main */
       public ClassASub()
          System.out.println("ClassASub Constructor");
       protected void myMethod()
          System.out.println("myMethod(SUB)");
       protected class ValueChecks extends ClassA.ValueChecks
          protected boolean checkMinimum()
             System.out.println("ValueChecks.checkMinimum (SUB)");
             return true;
    }The method myMethod seems to be suitably overridden, but I cannot override the checkMinimum() method.
    I think this is a stupid problem to do with how the ValueChecks class is instantiated. I think I need to create an instance of ValueChecks in ClassASub, and pass a reference to it into ClassA. But this will upset the way ClassA works. Could somebody enlighten me please.

    vc = new ValueChecks();vc is a ValueChecks object. No matter whether you subclass ValueChecks or not, vc is always of this type, per this line of code.
    // I want this to call the overridden method, but it does not, it seems to > call
    // the method in this class. probably because vc belongs to this class
    this.vc.checkMinimum();No, it's because again vc references a ValueChecks object, because it was created as such.
    And when I say ValueChecks, I mean the original class, not the one you tried to create by the same name, attempting to override the original.

  • How to override equals method

    The equals method accepts Object as the parameter. When overriding this method we need to downcast the parameter object to the specific. The downcast is not the good idea as it is not the OO. So can anyone please tell me how can we override the equals method without downcasting the parameter object. Thank you.

    For comparing the objects by value overriding the equals method what I did is like this
    public boolean equals(Object o){
        if( o instanceof Book){
            Book b = (Book)o;
            if(this.id == b.id)
                return true;
        return false;
    }But in the above code I have to downcast the object o to the class Book. This downcasting is not a good as it is not Object-Oriented. So what I want to do is avoid the downcasting. So any idea how to do it?

  • How to override ExecuteWithParms method?

    How I can override ExecuteWithParms method?
    as when click on execute button there are many parameters should return result from another table
    as select query from different table, can i do this? and how??

    thanks Timo. this is more detail
    I have two table Fundemental and Emails and I have many search parameters
    so I need to make custom adf search when click on execute search, get result from all search parameters
    so i need to override executeWithParms to change return value when search in pEmail parameter
    to return "ID_NO IN (SELECT PERSON_CODE FROM EMAILS WHERE EMAIL LIKE '%" + getpEmail()  + "%')";

  • How  to override toString() method ?

    class  Test
    String x[];
    int c;
    Test(int size)
    x=new String[size];
    c=-1;
    public void addString(String str)
    x=new String
    x[++c]=str;
    public void String toString()
    //  i want to override toString method to view the strings existing in the x[]...
    //   how do i view the strings ?
    //  probabily i should NOT use println() here (..as it is inside tostring() method ..right? )
    //   so i should  RETURN   x[] as an array...but the  toString() method return  type is String not the String array!.
    //   so i am in trouble.
    so in a simple way my question is how do i override toString() method to view the Strings stored in the array ?
    i am avoiding println() bcoz of bad design.
    }

    AS you said, the toString method returns a String - this String is supposed to be a representation of the current instance of your class's state. In your case, your class's state is a String array, so you just pick a format for that and make a String that fits that format. Maybe you want it to spit out something like:
    Test[1] = "some string"
    Test[2] = "some other String"If so, code something like:public String toString() {
        StringBuffer returnValue = new StringBuffer();
        for (int i = 0; i < x.length; i++) {
            returnValue.append("Test[" + i + "] = \"" + x[i] + "\"";
        return returnValue.toString();
    } If you don't mind the formatting of the toString method that Lists get, you could just do something like:public String toString() {
        return java.util.Arrays.asList(this).toString();
    } and call it good. That will print out something like:
    [Some String, another String, null]Depending on what's in your array.
    Good Luck
    Lee

Maybe you are looking for