| |

VerySource

 Forgot password?
 Register
Search
View: 928|Reply: 8

About Notepad !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!! 11

[Copy link]

2

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-1-18 19:00:01
| Show all posts |Read mode
import java.awt. *;
import java.awt.event. *;
import java.io. *;
import javax.swing. *;
import javax.swing.text. *;

// Simple text editor implements ActionListener
public class edit extends JFrame implements ActionListener {
JTextPane textPane = new JTextPane (); // Text pane, edit window
Ranch
JFileChooser filechooser = new JFileChooser (); // File selector

public edit () {// Constructor
super ("Simple text editor");
JMenuBar menubar = new JMenuBar ();
Container container = getContentPane (); // Get the container
Ranch
container.add (textPane, BorderLayout.CENTER); // Add text pane
container.add (menubar, BorderLayout.NORTH); // Add status bar

setSize (330, 200); // Set window size
setVisible (true); // Set window visible
setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); // Exit the program when the window is closed

JMenu menuFile = new JMenu ("File"); // Instantiate the menu
JMenu menuEdit = new JMenu ("Edit");
JMenu menuAbout = new JMenu ("Help");
JMenuItem menu1 = new JMenuItem ("New");
menu1.addActionListener (this);
menuFile.add (menu1);
Ranch
menubar.add (menuFile); // Add menu
menubar.add (menuEdit);
menubar.add (menuAbout);
Ranch
Ranch
}
Ranch
Ranch
Ranch
Ranch
Ranch
Ranch
Ranch
Ranch
public void actionPerformed (ActionEvent e)
{if (e.getSource () == menu1)
Ranch
 {
textPane.cut (); // Call the cut command of the text pane
}

}

Ranch
Ranch
Ranch
Ranch
Ranch
Ranch
Ranch
Ranch
Ranch
Ranch
Ranch
Ranch
Ranch
Ranch
Ranch
Ranch
public static void main (String [] args) {
new edit ();
}
Ranch
}



cannot resolve symbol varible menu1 ????????????????????????????????
Reply

Use magic Report

0

Threads

21

Posts

19.00

Credits

Newbie

Rank: 1

Credits
19.00

 China

Post time: 2020-1-25 12:27:01
| Show all posts
JMenuItem menu1 = new JMenuItem ("New");

Put on

public edit () {// Constructor

prior to

As member variable
Reply

Use magic Report

0

Threads

13

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-1-25 22:27:01
| Show all posts
ls positive solution, the other member functions written here cannot be called
Reply

Use magic Report

2

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-1-28 22:09:01
| Show all posts
import java.awt. *;
import java.awt.event. *;
import java.io. *;
import javax.swing. *;
import javax.swing.text. *;

// Simple text editor implements ActionListener
public class edit extends JFrame implements ActionListener {
JTextPane textPane = new JTextPane (); // Text pane, edit window
JFileChooser filechooser = new JFileChooser (); // File selector
JMenuBar menubar = new JMenuBar ();
JMenu menuFile = new JMenu ("File"); // Instantiate the menu
JMenu menuEdit = new JMenu ("Edit");
JMenu menuAbout = new JMenu ("Help");
JMenuItem menu1 = new JMenuItem ("New");
JMenuItem menu2 = new JMenuItem ("Open");
JMenuItem menu3 = new JMenuItem ("closed");
    JMenuItem menu4 = new JMenuItem ("Copy");
    JMenuItem menu5 = new JMenuItem ("Cut");
    JMenuItem menu6 = new JMenuItem ("Paste");
    JMenuItem menu7 = new JMenuItem ("Help");
        
       
    
public edit () {// Constructor
super ("Simple text editor");
Ranch
Container container = getContentPane (); // Get the container
Ranch
menu1.addActionListener (this);
menuFile.add (menu1);
Ranch
Ranch
menu2.addActionListener (this);
menuFile.add (menu2);
Ranch
Ranch
menu3.addActionListener (this);
menuFile.add (menu3);
Ranch
Ranch
menu4.addActionListener (this);
menuEdit.add (menu4);
Ranch
Ranch
menu5.addActionListener (this);
menuEdit.add (menu5);
Ranch
Ranch
menu6.addActionListener (this);
menuEdit.add (menu6);
Ranch
menu7.addActionListener (this);
menuAbout.add (menu7);
Ranch
menubar.add (menuFile);
menubar.add (menuEdit);
menubar.add (menuAbout);
Ranch
container.add (textPane, BorderLayout.CENTER); // Add text pane
container.add (menubar, BorderLayout.NORTH); // Add status bar
setSize (330, 200); // Set window size
setVisible (true); // Set window visible
setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); // Exit the program when the window is closed
Ranch
Ranch
Ranch
Ranch
Ranch
Ranch
}
Ranch
Ranch
Ranch
Ranch
Ranch
Ranch
Ranch
Ranch
public void actionPerformed (ActionEvent e) {
       
       if (e.getSource () == menu1) {
Ranch
        textPane.setDocument (new DefaultStyledDocument ());} // Empty the document
Ranch
if (e.getSource () == menu2) {
int i = filechooser.showOpenDialog (edit.this); // Show open file dialog
Ranch
Ranch
if (i == JFileChooser.APPROVE_OPTION) {// Click the dialog box to open the option
File f = filechooser.getSelectedFile (); // Get the selected file
try {
InputStream is = new FileInputStream (f); // Get file input stream
textPane.read (is, "d"); // Read the file into the text pane
} catch (Exception ex) {
ex.printStackTrace (); // Output error information
}
}
}
Ranch
Ranch
       if (e.getSource () == menu3) {
Ranch
        System.exit (0);} // Exit the program
     
     
       if (e.getSource () == menu4) {
    textPane.copy ();} // Call the copy command of the text pane
Ranch
if (e.getSource () == menu5) {
        textPane.cut ();} // Call the cut command of the text pane
        
        if (e.getSource () == menu5) {
       textPane.paste ();} // Invoke the paste command of the text pane
        
       if (e.getSource () == menu7) {
       JOptionPane.showMessageDialog (edit.this, "Simple text editor demo");} // Show software information
     
}


Ranch
Ranch
Ranch
public static void main (String [] args) {
new edit ();}
Ranch
Ranch
}


The problem was solved just now Thank you !!!!!!!!!!!!!!!
However, copying and pasting is still not possible. Every time I select the text and then select the copy and paste command on the menu, the selected text immediately becomes unselected. What is going on?
Reply

Use magic Report

1

Threads

20

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

Post time: 2020-1-29 22:18:01
| Show all posts
if (e.getSource () == menu5) {
       textPane.paste ();} // Invoke the paste command of the text pane

To:
  if (e.getSource () == menu6) {
       textPane.paste ();} // Invoke the paste command of the text pane
Reply

Use magic Report

2

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-1-30 03:36:02
| Show all posts
Dizzy, thank you !!!!! 111
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-2-4 12:30:01
| Show all posts
I just made one and realized the new, open, save, save as, exit functions, and have the opportunity to communicate!
Reply

Use magic Report

2

Threads

11

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-2-12 19:45:01
| Show all posts
h12345b, I also wrote a relatively simple one, can you post it?
Reply

Use magic Report

2

Threads

11

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-5-6 11:00:01
| Show all posts
container.add (menubar, BorderLayout.NORTH); // Add status bar
This is wrong, you are adding a menu bar, not a status bar, but the menu bar is independent of the container
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list