Question:
How to create a Replace class [JAVA]?
Saula
2010-05-20 22:59:35 UTC
Implement a Replace dialog as a separate class that will do both case sensitive and case insensitive search-and-replace on all of the text area. The dialog should provide ‘find’ and ‘replace’ value fields, a check box for the option to perform a case insensitive search, a Replace All button to perform the replacement and a Close button to exit the form. The total number of replacements done should be displayed in a status bar at the bottom of the dialog screen. The dialog should be a subclass of JDialog and should accept the owner form and JTextArea from the calling program. The dialog should be displayed in a modal manner. The Dialog should be displayed centered over the parent window.

Below is the class declaration that should be used as well as the constructor.

public class Replace extends JDialog{

public Replace(Frame owner, JTextArea textToReplace )

{

}

}
Three answers:
deonejuan
2010-05-21 01:02:12 UTC
// here is a basic sketch outline



public class ReplaceDialog extends JDialog {



MainFrame mainFrame;



public ReplaceDialog( MainFrame mainFrame ) {

this.mainFrame = mainFrame;



JComponent replacePanel = new ReplacePanel( mainFrame ).getComponent();

add( replacePanel );

this.pack();

this.setLocationRelativeTo( mainFrame );

this.setVisible( true );

}



private class ReplacePanel extends JComponent {



private JPanel mainPanel = new JPanel();

private JFrame controllingFrame;



public ReplacePanel( final JFrame controllingFrame ) {

this.controllingFrame = controllingFrame;

mainPanel.setLayout( new GridLayout( 3,1,0,0 ) );

mainPanel.setBorder( BorderFactory.createEmptyBorder( 5,2,5,2 ) );

JPanel optionPanel = new JPanel();

// set layout to have a label and OptionButton

JPanel textPanel = new JPanel();

JPanel btnPanel = new JPanel();

// setLayout to have two JButtons

JButton btnClose = new JButton("Close");

btnClose.addActionListener( new ActionListener() {

public void actionPerformed( ActionEvent e ) {

this.setVisible( false );

// do any text saves

} );

mainPanel.add(optionsPanel);

mainPanel.add( textPanel);

mainPanel.add( btnPanel);

mainPanel.add( infoLabel);

}

public JComponent getComponent() {

return main Panel;

}

}

}
rampaal
2016-12-16 13:51:25 UTC
you won't be able to instantiate an Interface. substitute your 2nd line to a minimum of a few thing like: dinosaur = new ArrayList(); or dinosaur = new LinkedList(); or another concrete implementation of a catalogue.
anonymous
2010-05-20 23:10:36 UTC
the base class members are inherited and you can override any inherited functions you want to change, and add new functions you want to add.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...