Skip to content

Commit 86b2920

Browse files
committed
Stable Release OpenJDK 19.0.1
0 parents  commit 86b2920

13 files changed

Lines changed: 394 additions & 0 deletions

File tree

pom.xml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.example</groupId>
8+
<artifactId>notepad</artifactId>
9+
<version>1.4</version>
10+
11+
<name>notepad</name>
12+
<!-- FIXME change it to the project's website -->
13+
<url>http://www.example.com</url>
14+
15+
<properties>
16+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
17+
<maven.compiler.source>1.8</maven.compiler.source>
18+
<maven.compiler.target>1.8</maven.compiler.target>
19+
</properties>
20+
21+
<dependencies>
22+
23+
<dependency>
24+
<groupId>org.openjfx</groupId>
25+
<artifactId>javafx</artifactId>
26+
<version>20-ea+7</version>
27+
<type>pom</type>
28+
</dependency>
29+
30+
<dependency>
31+
<groupId>junit</groupId>
32+
<artifactId>junit</artifactId>
33+
<version>4.11</version>
34+
<scope>test</scope>
35+
</dependency>
36+
</dependencies>
37+
38+
<build>
39+
<plugins>
40+
<plugin>
41+
<artifactId>maven-assembly-plugin</artifactId>
42+
<configuration>
43+
<archive>
44+
<manifest>
45+
<mainClass>com.example.App</mainClass>
46+
</manifest>
47+
</archive>
48+
<descriptorRefs>
49+
<descriptorRef>jar-with-dependencies</descriptorRef>
50+
</descriptorRefs>
51+
</configuration>
52+
<executions>
53+
<execution>
54+
<id>make-assembly</id> <!-- this is used for inheritance merges -->
55+
<phase>package</phase> <!-- bind to the packaging phase -->
56+
<goals>
57+
<goal>single</goal>
58+
</goals>
59+
</execution>
60+
</executions>
61+
</plugin>
62+
</plugins>
63+
</build>
64+
65+
</project>

src/main/java/com/example/App.java

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
package com.example;
2+
3+
import java.awt.event.*;
4+
import java.io.BufferedReader;
5+
import java.io.BufferedWriter;
6+
import java.io.File;
7+
import java.io.FileNotFoundException;
8+
import java.io.FileReader;
9+
import java.io.FileWriter;
10+
11+
import javax.swing.*;
12+
13+
public class App extends JFrame implements ActionListener {
14+
JTextArea t;
15+
JFrame f;
16+
17+
App() {
18+
f = new JFrame("notepad");
19+
t = new JTextArea();
20+
21+
JMenuBar mb = new JMenuBar();
22+
23+
JMenu m1 = new JMenu("File");
24+
JMenu m2 = new JMenu("Edit");
25+
26+
JMenuItem mi1 = new JMenuItem("New");
27+
JMenuItem mi2 = new JMenuItem("Open");
28+
JMenuItem mi3 = new JMenuItem("Save");
29+
JMenuItem mi8 = new JMenuItem("Save as");
30+
JMenuItem mi9 = new JMenuItem("Print");
31+
32+
JMenuItem mi4 = new JMenuItem("cut");
33+
JMenuItem mi5 = new JMenuItem("copy");
34+
JMenuItem mi6 = new JMenuItem("paste");
35+
JMenuItem mc = new JMenuItem("close");
36+
37+
mi1.addActionListener(this);
38+
mi2.addActionListener(this);
39+
mi3.addActionListener(this);
40+
mi8.addActionListener(this);
41+
mi9.addActionListener(this);
42+
43+
mi4.addActionListener(this);
44+
mi5.addActionListener(this);
45+
mi6.addActionListener(this);
46+
47+
mc.addActionListener(this);
48+
49+
m1.add(mi1);
50+
m1.add(mi2);
51+
m1.add(mi3);
52+
m1.add(mi8);
53+
m1.add(mi9);
54+
55+
m2.add(mi4);
56+
m2.add(mi5);
57+
m2.add(mi6);
58+
59+
mb.add(m1);
60+
mb.add(m2);
61+
mb.add(mc);
62+
63+
f.setJMenuBar(mb);
64+
f.add(t);
65+
f.setSize(500, 500);
66+
f.setLocationRelativeTo(null);
67+
f.setResizable(true);
68+
f.setVisible(true);
69+
70+
f.addWindowListener(new WindowAdapter() {
71+
/**
72+
* @description: calls the kill() method if windows x button is clicked and performs the same action as close().
73+
*/
74+
@Override
75+
public void windowClosing(WindowEvent e) {
76+
if (kill() == 1) {
77+
f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
78+
}
79+
}
80+
});
81+
}
82+
83+
/**
84+
* @param ActionEvent Action Event listner for menu items
85+
* @description Listens to the menu items and performs an action based on the
86+
* menu item selected
87+
*/
88+
public void actionPerformed(ActionEvent e) {
89+
String s = e.getActionCommand();
90+
JFileChooser j;
91+
int r;
92+
String path = "";
93+
94+
if (s.equals("cut")) {
95+
t.cut();
96+
}
97+
98+
if (s.equals("copy")) {
99+
t.copy();
100+
}
101+
if (s.equals("paste")) {
102+
t.paste();
103+
}
104+
if (s.equals("Save")) {
105+
if (path.equals("")) {
106+
path = save();
107+
} else {
108+
try {
109+
System.out.println("in loop");
110+
FileWriter fw = new FileWriter(path);
111+
BufferedWriter bw = new BufferedWriter(fw);
112+
t.write(bw);
113+
bw.close();
114+
} catch (Exception evt) {
115+
JOptionPane.showMessageDialog(f, "Saving error" + evt.getMessage());
116+
}
117+
}
118+
}
119+
if (s.equals("Save as")) {
120+
path = save();
121+
}
122+
if (s.equals("Print")) {
123+
try {
124+
t.print();
125+
} catch (Exception evt) {
126+
JOptionPane.showMessageDialog(f, "Printing error" + evt.getMessage());
127+
}
128+
}
129+
if (s.equals("New")) {
130+
if (t.getText().equals("")) {
131+
t.setText("");
132+
} else {
133+
path = save();
134+
135+
}
136+
}
137+
if (s.equals("Open")) {
138+
j = new JFileChooser("C:");
139+
140+
r = j.showOpenDialog(null);
141+
142+
if (r == JFileChooser.APPROVE_OPTION) {
143+
j = new JFileChooser("C:");
144+
145+
File fi = new File(j.getSelectedFile().getAbsolutePath());
146+
try {
147+
String s1 = "", sl = "";
148+
FileReader fr = new FileReader(fi);
149+
try (
150+
BufferedReader br = new BufferedReader(fr)) {
151+
sl = br.readLine();
152+
while ((s1 = br.readLine()) != null) {
153+
sl = sl + " " + s1;
154+
}
155+
if (sl != null) {
156+
t.setText(sl);
157+
}
158+
}
159+
t.setText(sl);
160+
161+
} catch (FileNotFoundException e1) {
162+
JOptionPane.showMessageDialog(f, "File not found");
163+
} catch (Exception e1) {
164+
JOptionPane.showMessageDialog(f, "Error in reading" + e1.getMessage());
165+
} finally {
166+
JOptionPane.showMessageDialog(f, "File opened successfully");
167+
}
168+
}
169+
}
170+
if (s.equals("close")) {
171+
kill();
172+
}
173+
}
174+
175+
/**
176+
* @description Saves the file to specified path and returns the path (acts as a saveas function basically)
177+
* @return String path of the file
178+
*/
179+
public String save() {
180+
JFileChooser j = new JFileChooser("C:");
181+
182+
int r = j.showSaveDialog(null);
183+
184+
if (r == JFileChooser.APPROVE_OPTION) {
185+
186+
File fi = new File(j.getSelectedFile().getAbsolutePath());
187+
188+
try {
189+
FileWriter wr = new FileWriter(fi, false);
190+
BufferedWriter w = new BufferedWriter(wr);
191+
192+
w.write(t.getText());
193+
w.flush();
194+
w.close();
195+
196+
return fi.getAbsolutePath();
197+
} catch (Exception evt) {
198+
JOptionPane.showMessageDialog(f, "Saving error" + evt.getMessage());
199+
}
200+
} else
201+
JOptionPane.showMessageDialog(f, "Cancelled saving");
202+
return null;
203+
}
204+
205+
/**
206+
* @description asks the user if wants to save the file before closing application
207+
* @return int 1 if the user wants to continue editing (cancel)
208+
*/
209+
private int kill() {
210+
int a = JOptionPane.showConfirmDialog(f, "Do you want to save the file before exiting?");
211+
212+
if (a == JOptionPane.YES_OPTION) {
213+
save();
214+
System.exit(0);
215+
} else if (a == JOptionPane.NO_OPTION) {
216+
System.exit(0);
217+
}
218+
return 1;
219+
}
220+
221+
public static void main(String args[]) {
222+
launch();
223+
}
224+
225+
/**
226+
* @description Launches the application
227+
*/
228+
private static void launch() {
229+
new App();
230+
}
231+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.example;
2+
3+
import static org.junit.Assert.assertTrue;
4+
5+
import org.junit.Test;
6+
7+
/**
8+
* Unit test for simple App.
9+
*/
10+
public class AppTest
11+
{
12+
/**
13+
* Rigorous Test :-)
14+
*/
15+
@Test
16+
public void shouldAnswerWithTrue()
17+
{
18+
assertTrue( true );
19+
}
20+
}
785 Bytes
Binary file not shown.
6.05 KB
Binary file not shown.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#Created by Apache Maven 3.8.6
2+
artifactId=notepad
3+
groupId=com.example
4+
version=1.4
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
com\example\App$1.class
2+
com\example\App.class
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
C:\dev\java\music\musicplayerTest\notepad\src\main\java\com\example\App.java
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
com\example\AppTest.class
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
C:\dev\java\music\musicplayerTest\notepad\src\test\java\com\example\AppTest.java

0 commit comments

Comments
 (0)