This repository has been archived by the owner on Feb 4, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 41
Added Text Editor Application #70
Open
smv1999
wants to merge
3
commits into
Design-and-Code:main
Choose a base branch
from
smv1999:notepad_app
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
https://github.com/smv1999/BoraxCode |
209 changes: 209 additions & 0 deletions
209
public/Projects/Vaidhyanathan S M/BoraxCode/editor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,209 @@ | ||
|
||
// Java Program to create a text editor using java | ||
import java.awt.*; | ||
import javax.swing.*; | ||
import java.io.*; | ||
import java.awt.event.*; | ||
import javax.swing.plaf.metal.*; | ||
import javax.swing.text.*; | ||
|
||
import javafx.stage.Modality; | ||
|
||
class editor extends JFrame implements ActionListener { | ||
// Text component | ||
JTextArea t; | ||
|
||
// Frame | ||
JFrame f; | ||
|
||
// Constructor | ||
editor() { | ||
|
||
f = new JFrame("Borax Code"); | ||
|
||
ImageIcon img = new ImageIcon("text-editor-icon.png"); | ||
f.setIconImage(img.getImage()); | ||
|
||
try { | ||
// Set metl look and feel | ||
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); // javax.swing.plaf.windows.WindowsLookAndFeel | ||
|
||
} catch (Exception e) { | ||
} | ||
|
||
// Text component | ||
|
||
t = new JTextArea(); | ||
|
||
t.setFont(t.getFont().deriveFont(20f)); | ||
|
||
JScrollPane scroll = new JScrollPane(t); | ||
scroll.setPreferredSize(t.getPreferredSize()); | ||
scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); | ||
|
||
// Create a menubar | ||
JMenuBar mb = new JMenuBar(); | ||
|
||
// Create a menu for menu | ||
JMenu m1 = new JMenu("File"); | ||
|
||
m1.setPreferredSize(new Dimension(80, m1.getPreferredSize().height)); | ||
|
||
// Create menu items | ||
JMenuItem mi1 = new JMenuItem("New"); | ||
JMenuItem mi2 = new JMenuItem("Open"); | ||
JMenuItem mi3 = new JMenuItem("Save"); | ||
JMenuItem mi9 = new JMenuItem("Print"); | ||
|
||
mb.add(Box.createVerticalGlue()); | ||
|
||
// Add action listener | ||
mi1.addActionListener(this); | ||
mi2.addActionListener(this); | ||
mi3.addActionListener(this); | ||
mi9.addActionListener(this); | ||
|
||
m1.add(mi1); | ||
m1.add(mi2); | ||
m1.add(mi3); | ||
m1.add(mi9); | ||
|
||
// Create amenu for menu | ||
JMenu m2 = new JMenu("Edit"); | ||
m2.setPreferredSize(new Dimension(80, m2.getPreferredSize().height)); | ||
|
||
// Create menu items | ||
JMenuItem mi4 = new JMenuItem("cut"); | ||
JMenuItem mi5 = new JMenuItem("copy"); | ||
JMenuItem mi6 = new JMenuItem("paste"); | ||
|
||
// Add action listener | ||
mi4.addActionListener(this); | ||
mi5.addActionListener(this); | ||
mi6.addActionListener(this); | ||
|
||
m2.add(mi4); | ||
m2.add(mi5); | ||
m2.add(mi6); | ||
|
||
JMenuItem mc = new JMenuItem("Close"); | ||
|
||
mc.addActionListener(this); | ||
|
||
mb.add(m1); | ||
mb.add(m2); | ||
mb.add(mc); | ||
|
||
f.setJMenuBar(mb); | ||
f.add(t); | ||
f.setSize(1000, 1000); | ||
f.setVisible(true); | ||
} | ||
|
||
// If a button is pressed | ||
public void actionPerformed(ActionEvent e) { | ||
String s = e.getActionCommand(); | ||
|
||
if (s.equals("cut")) { | ||
t.cut(); | ||
} else if (s.equals("copy")) { | ||
t.copy(); | ||
} else if (s.equals("paste")) { | ||
t.paste(); | ||
} else if (s.equals("Save")) { | ||
// Create an object of JFileChooser class | ||
JFileChooser j = new JFileChooser("f:"); | ||
|
||
// Invoke the showsSaveDialog function to show the save dialog | ||
int r = j.showSaveDialog(null); | ||
|
||
if (r == JFileChooser.APPROVE_OPTION) { | ||
|
||
// Set the label to the path of the selected directory | ||
File fi = new File(j.getSelectedFile().getAbsolutePath()); | ||
|
||
try { | ||
// Create a file writer | ||
FileWriter wr = new FileWriter(fi, false); | ||
|
||
// Create buffered writer to write | ||
BufferedWriter w = new BufferedWriter(wr); | ||
|
||
// Write | ||
w.write(t.getText()); | ||
|
||
w.flush(); | ||
w.close(); | ||
} catch (Exception evt) { | ||
JOptionPane.showMessageDialog(f, evt.getMessage()); | ||
} | ||
JOptionPane.showMessageDialog(f, "The file has been successfully saved!"); | ||
|
||
} | ||
// If the user cancelled the operation | ||
else | ||
JOptionPane.showMessageDialog(f, "You have cancelled the save!"); | ||
} else if (s.equals("Print")) { | ||
try { | ||
// print the file | ||
t.print(); | ||
} catch (Exception evt) { | ||
JOptionPane.showMessageDialog(f, evt.getMessage()); | ||
} | ||
} else if (s.equals("Open")) { | ||
// Create an object of JFileChooser class | ||
JFileChooser j = new JFileChooser("f:"); | ||
|
||
// Invoke the showsOpenDialog function to show the save dialog | ||
int r = j.showOpenDialog(null); | ||
|
||
// If the user selects a file | ||
if (r == JFileChooser.APPROVE_OPTION) { | ||
// Set the label to the path of the selected directory | ||
File fi = new File(j.getSelectedFile().getAbsolutePath()); | ||
|
||
try { | ||
// String | ||
String s1 = "", sl = ""; | ||
|
||
// File reader | ||
FileReader fr = new FileReader(fi); | ||
|
||
// Buffered reader | ||
BufferedReader br = new BufferedReader(fr); | ||
|
||
// Initilize sl | ||
sl = br.readLine(); | ||
|
||
// Take the input from the file | ||
while ((s1 = br.readLine()) != null) { | ||
sl = sl + "\n" + s1; | ||
} | ||
|
||
// Set the text | ||
t.setText(sl); | ||
} catch (Exception evt) { | ||
JOptionPane.showMessageDialog(f, evt.getMessage()); | ||
} | ||
|
||
} | ||
// If the user cancelled the operation | ||
else | ||
JOptionPane.showMessageDialog(f, "You have cancelled the print!"); | ||
} else if (s.equals("New")) { | ||
t.setText(""); | ||
} | ||
|
||
else if (s.equals("Close")) { | ||
// f.setVisible(false); | ||
f.dispatchEvent(new WindowEvent(f, WindowEvent.WINDOW_CLOSING)); | ||
|
||
} | ||
|
||
} | ||
|
||
// Main class | ||
public static void main(String args[]) { | ||
editor e = new editor(); | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove some white lines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made the changes