-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Asyfero
committed
Dec 7, 2021
1 parent
bb8634a
commit 3438f07
Showing
4 changed files
with
140 additions
and
41 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
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 |
---|---|---|
@@ -1,48 +1,13 @@ | ||
// Import package | ||
package fr.asyfero.gui; | ||
|
||
// import all dependencies | ||
import javax.swing.*; | ||
import java.awt.*; | ||
// Import class | ||
import fr.asyfero.gui.utilities.app; | ||
|
||
public class gui { | ||
public static void main(String[] args){ | ||
// Create the gui/app | ||
JFrame frame = new JFrame("App"); | ||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
frame.setSize(300, 300); | ||
|
||
// Show message when the app start | ||
JOptionPane.showMessageDialog(frame, "Welcome!\nThis is a basic app made in java!\n\nMade by Asyfero\n\nThe project is on Github:\nhttps://github.com/Asyfero/Java-gui", "App Start Message", JOptionPane.PLAIN_MESSAGE); | ||
|
||
// Create menu bar up of app | ||
JMenuBar menuBar = new JMenuBar(); | ||
JMenu m1 = new JMenu("File"); | ||
JMenu m2 = new JMenu("Edit"); | ||
JMenu m3 = new JMenu("Help"); | ||
menuBar.add(m1); | ||
menuBar.add(m2); | ||
menuBar.add(m3); | ||
|
||
// Make options for 'File' button | ||
JMenuItem m11 = new JMenuItem("Open"); | ||
JMenuItem m12 = new JMenuItem("Save"); | ||
JMenuItem m13 = new JMenuItem("Save As"); | ||
m1.add(m11); | ||
m1.add(m12); | ||
m1.add(m13); | ||
|
||
// Make options for 'Edit' button | ||
JMenuItem m21 = new JMenuItem("Rename"); | ||
JMenuItem m22 = new JMenuItem("Delete"); | ||
m2.add(m21); | ||
m2.add(m22); | ||
|
||
// Make options for 'Help' button | ||
JMenuItem m31 = new JMenuItem("Welcome Message"); | ||
m3.add(m31); | ||
|
||
// Set visible all content | ||
frame.getContentPane().add(BorderLayout.NORTH, menuBar); | ||
frame.setVisible(true); | ||
// Start the app using start method | ||
app a = new app(); | ||
a.start(); | ||
} | ||
} |
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,134 @@ | ||
package fr.asyfero.gui.utilities; | ||
|
||
import javax.swing.*; | ||
import java.awt.*; | ||
import java.awt.event.ActionEvent; | ||
import java.awt.event.ActionListener; | ||
import java.io.*; | ||
|
||
public class app extends JFrame implements ActionListener { | ||
JTextArea t; | ||
JFrame frame; | ||
|
||
public void start() { | ||
// Create the gui/app | ||
frame = new JFrame("App"); | ||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
frame.setSize(300, 300); | ||
|
||
// Create Text Area | ||
t = new JTextArea(); | ||
|
||
// Show message when the app start | ||
JOptionPane.showMessageDialog(frame, "Welcome!\nThis is a basic app made in java!\n\nMade by Asyfero\n\nThe project is on Github:\nhttps://github.com/Asyfero/Java-gui", "App Start Message", JOptionPane.PLAIN_MESSAGE); | ||
|
||
// Create menu bar up of app | ||
JMenuBar menuBar = new JMenuBar(); | ||
JMenu m1 = new JMenu("File"); | ||
JMenu m3 = new JMenu("Help"); | ||
menuBar.add(m1); | ||
menuBar.add(m3); | ||
|
||
// Make options for 'File' button | ||
JMenuItem m11 = new JMenuItem("New"); | ||
JMenuItem m12 = new JMenuItem("Close"); | ||
JMenuItem m13 = new JMenuItem("Open"); | ||
JMenuItem m14 = new JMenuItem("Save"); | ||
m1.add(m11); | ||
m1.add(m12); | ||
m1.add(m13); | ||
m1.add(m14); | ||
|
||
// Make options for 'Help' button | ||
JMenuItem m31 = new JMenuItem("Welcome Message"); | ||
m3.add(m31); | ||
|
||
// Add Action Listener | ||
m11.addActionListener(this); | ||
m12.addActionListener(this); | ||
m13.addActionListener(this); | ||
m14.addActionListener(this); | ||
|
||
m31.addActionListener(this); | ||
|
||
// Set visible all content | ||
frame.getContentPane().add(BorderLayout.NORTH, menuBar); | ||
frame.add(t); | ||
frame.setVisible(true); | ||
} | ||
|
||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
String s = e.getActionCommand(); | ||
|
||
switch (s) { | ||
case "New": | ||
t.setText(""); | ||
t.setVisible(true); | ||
break; | ||
case "Close": | ||
t.setVisible(false); | ||
break; | ||
case "Print": | ||
try { | ||
t.print(); | ||
}catch (Exception evt) { | ||
JOptionPane.showMessageDialog(frame, evt.getMessage()); | ||
} | ||
break; | ||
case "Open": { | ||
JFileChooser file = new JFileChooser("f:"); | ||
|
||
int r = file.showOpenDialog(null); | ||
|
||
if (r == JFileChooser.APPROVE_OPTION) { | ||
File fi = new File(file.getSelectedFile().getAbsolutePath()); | ||
|
||
try { | ||
String s1 = "", sl = ""; | ||
|
||
FileReader fr = new FileReader(fi); | ||
|
||
BufferedReader br = new BufferedReader(fr); | ||
|
||
sl = br.readLine(); | ||
|
||
while ((s1 = br.readLine()) != null) { | ||
sl = sl + "\n" + s1; | ||
} | ||
t.setText(sl); | ||
} catch (Exception evt) { | ||
JOptionPane.showMessageDialog(frame, evt.getMessage()); | ||
} | ||
} | ||
break; | ||
} | ||
case "Save": { | ||
JFileChooser file = new JFileChooser("f:"); | ||
|
||
int r = file.showSaveDialog(null); | ||
|
||
if (r == JFileChooser.APPROVE_OPTION) { | ||
File fi = new File(file.getSelectedFile().getAbsolutePath()); | ||
|
||
try { | ||
FileWriter wr = new FileWriter(fi, false); | ||
|
||
BufferedWriter bw = new BufferedWriter(wr); | ||
|
||
bw.write(t.getText()); | ||
|
||
bw.flush(); | ||
bw.close(); | ||
} catch (Exception evt) { | ||
JOptionPane.showMessageDialog(frame, evt.getMessage()); | ||
} | ||
} | ||
break; | ||
} | ||
case "Welcome Message": | ||
JOptionPane.showMessageDialog(frame, "Welcome!\nThis is a basic app made in java!\n\nMade by Asyfero\n\nThe project is on Github:\nhttps://github.com/Asyfero/Java-gui", "App Start Message", JOptionPane.PLAIN_MESSAGE); | ||
break; | ||
} | ||
} | ||
} |