Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Samielleuch/1d891eaad5d06f5881c6ca42e08e1ebf to your computer and use it in GitHub Desktop.
Save Samielleuch/1d891eaad5d06f5881c6ca42e08e1ebf to your computer and use it in GitHub Desktop.
javaproject
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with NO BOM" />
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/JavaProjectWordApp.iml" filepath="$PROJECT_DIR$/JavaProjectWordApp.iml" />
</modules>
</component>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class ChangeColorListener implements ActionListener {
Panel panelBackground;
Panel panelwork;
Panel panelbtns;
Panel p;
TextArea txt;
Frame f;
public ChangeColorListener(Panel panelBackground, Panel panelwork, Panel panelbtns, Panel p, TextArea txt, Frame f) {
this.panelBackground = panelBackground;
this.panelwork = panelwork;
this.panelbtns = panelbtns;
this.p = p;
this.f = f;
this.txt = txt;
}
public void actionPerformed(ActionEvent e) {
Frame fr = new Frame("Color Name");
fr.setBounds(355, 355, 355, 200);
fr.setLayout(new GridLayout(7, 1));
Label lb = new Label("enter R");
TextField rr = new TextField();
Label lb2 = new Label("enter G");
TextField gg = new TextField();
Label lb3 = new Label("enter B");
TextField bb = new TextField();
Button submit = new Button("Submit");
fr.add(lb);
fr.add(rr);
fr.add(lb2);
fr.add(gg);
fr.add(lb3);
fr.add(bb);
fr.add(submit);
fr.setVisible(true);
//submit Action
submit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int r = Integer.parseInt(rr.getText());
int g = Integer.parseInt(gg.getText());
int b = Integer.parseInt(bb.getText());
Color cl = new Color(r, g, b);
txt.setForeground(cl);
fr.setVisible(false);
}
});
}
}
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class ChangeFontListener implements ActionListener {
Panel panelBackground;
Panel panelwork;
Panel panelbtns;
Panel p;
TextArea txt;
Frame f;
public ChangeFontListener(Panel panelBackground, Panel panelwork, Panel panelbtns, Panel p, TextArea txt, Frame f) {
this.panelBackground = panelBackground;
this.panelwork = panelwork;
this.panelbtns = panelbtns;
this.p = p;
this.f = f;
this.txt = txt;
}
public void actionPerformed(ActionEvent e) {
Frame fr = new Frame("change the font");
fr.setBounds(355, 355, 355, 200);
fr.setLayout(new GridLayout(7, 1));
Label lb = new Label("font name");
TextField name = new TextField();
Label lb2 = new Label("font type");
List li = new List(3, false);
li.add("Plain");
li.add("Bold");
li.add("Italic");
Label lb3 = new Label("font size");
TextField size = new TextField();
Button submit = new Button("Submit");
fr.add(lb);
fr.add(name);
fr.add(lb2);
fr.add(li);
fr.add(lb3);
fr.add(size);
fr.add(submit);
fr.setVisible(true);
//submit Action
submit.addActionListener(new ActionListener() {
//bold 1
// italic 2
// plain 0 ;
public void actionPerformed(ActionEvent e) {
String nameu = name.getText();
int Type = li.getSelectedIndex();
int Size = Integer.parseInt(size.getText());
Font font = new Font(nameu, Type, Size);
txt.setFont(font);
fr.setVisible(false);
}
});
}
}
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class FindAndReplaceListener implements ActionListener {
Panel panelBackground;
Panel panelwork;
Panel panelbtns;
Panel p;
TextArea txt;
Frame f;
public FindAndReplaceListener(Panel panelBackground, Panel panelwork, Panel panelbtns, Panel p, TextArea txt, Frame f) {
this.panelBackground = panelBackground;
this.panelwork = panelwork;
this.panelbtns = panelbtns;
this.p = p;
this.f = f;
this.txt = txt;
}
public void actionPerformed(ActionEvent e) {
Frame fr = new Frame("Enter Find keyword");
fr.setBounds(355, 355, 355, 200);
fr.setLayout(new GridLayout(3, 1));
TextArea query = new TextArea();
TextArea replace = new TextArea();
Button submit = new Button("Submit");
fr.add(query);
fr.add(replace);
fr.add(submit);
fr.setVisible(true);
//submit Action
submit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String search = query.getText();
String repl = replace.getText();
String text = txt.getText();
int offset = text.indexOf(search);
int length = search.length();
text = text.replaceAll(search, repl);
System.out.println(text);
txt.setText(text);
fr.setVisible(false);
}
});
}
}
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class FindListener implements ActionListener {
Panel panelBackground;
Panel panelwork;
Panel panelbtns;
Panel p;
TextArea txt;
Frame f;
public FindListener(Panel panelBackground, Panel panelwork, Panel panelbtns, Panel p, TextArea txt, Frame f) {
this.panelBackground = panelBackground;
this.panelwork = panelwork;
this.panelbtns = panelbtns;
this.p = p;
this.f = f;
this.txt = txt;
}
public void actionPerformed(ActionEvent e) {
Frame fr = new Frame("Enter Find keyword");
fr.setBounds(355, 355, 355, 200);
fr.setLayout(new GridLayout(2, 1));
TextArea query = new TextArea();
Button submit = new Button("Submit");
fr.add(query);
fr.add(submit);
fr.setVisible(true);
//submit Action
submit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String search = query.getText();
String text = txt.getText();
int offset = text.indexOf(search);
int length = search.length();
String result = "the searched word is on the index " + offset + "and its length is " + length;
fr.remove(submit);
query.setText(result);
Button end = new Button("finish");
fr.add(end);
end.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
fr.setVisible(false);
}
});
}
});
}
}
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class MyFrame extends Frame {
private Panel panelBackground;
private Panel panelwork;
private Panel panelbtns;
private MyMenuBar menuBar;
private TextArea txt = new TextArea();
public MyFrame() {
super("WordApp");
this.setBounds(250, 300, 900, 900);
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
super.windowClosing(e);
System.exit(0);
}
});
// bachground + text animation
panelBackground = new Panel() {
int x = 0;
public void paint(Graphics g) {
super.paint(g);
Graphics2D g2 = (Graphics2D) g;
Image img = Toolkit.getDefaultToolkit().getImage("./imgs/Background.jpg");
g2.drawImage(img, 0, 0, getSize().width, getSize().height, this);
Font f = new Font("Serif", Font.BOLD, 32);
g2.setFont(f);
g2.drawString("PLease Open or Create a new Project to Start using the app :D", x, getHeight() / 2);
try {
Thread.sleep(60);
} catch (Exception e) {
}
x++;
if (x > getWidth()) {
x = 0;
}
repaint();
}
};
// text editor panel
panelwork = new Panel() {
int x = 0;
public void paint(Graphics g) {
super.paint(g);
Graphics2D g2 = (Graphics2D) g;
Font f = new Font("Serif", Font.BOLD, 32);
g2.setFont(f);
g2.drawString("you can use the butons or the menu ", x, getHeight() * 4 / 5);
try {
Thread.sleep(60);
} catch (Exception e) {
}
x++;
if (x > getWidth()) {
x = 0;
}
repaint();
}
};
//empty panels
Panel p = new Panel();
p.setBackground(new Color(164, 162, 131, 0));
//p.setBounds(0,0,200,getHeight());
// btn control Panels
panelbtns = new Panel();
panelbtns.setBackground(new Color(164, 162, 131, 0));
panelBackground.setLayout(new BorderLayout());
panelBackground.add(panelbtns, BorderLayout.NORTH);
this.add(panelBackground);
Frame f = this;
//open btn
Button op = new Button("**OPEN A PROJECT **");
//create btn
Button cr = new Button("**CREATE A PROJECT **");
// add btns to btnpanel
panelbtns.add(op);
panelbtns.add(cr);
//********************Buttons Action Listners//*************
//open Listener
op.addActionListener(new OpenListener(panelBackground, panelwork, panelbtns, p, txt, this));
//New Listener
cr.addActionListener(new NewListener(panelBackground, panelwork, panelbtns, p, txt, this));
//menuBar
menuBar = new MyMenuBar(panelBackground, panelwork, panelbtns, p, txt, this);
this.setMenuBar(menuBar);
this.setVisible(true);
}
}
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class MyMenuBar extends MenuBar {
private Menu file = new Menu("File");
private MenuItem open = new MenuItem("Open");
private MenuItem New = new MenuItem("New");
private MenuItem rename = new MenuItem("Rename");
private MenuItem save = new MenuItem("Save");
private MenuItem exit = new MenuItem("Exit");
private MenuItem Find = new MenuItem("Find");
private MenuItem Findrep = new MenuItem("Find & Replace");
private MenuItem chcol = new MenuItem("Change Font Color");
private MenuItem chfont = new MenuItem("Change Font & Font Size");
private Menu edit = new Menu("Edit");
public MyMenuBar(Panel panelBackground, Panel panelwork, Panel panelbtns, Panel p, TextArea txt, Frame f) {
this.add(file);
this.add(edit);
edit.add(Find);
edit.add(Findrep);
edit.add(chcol);
edit.add(chfont);
file.add(open);
file.add(New);
file.add(rename);
file.add(save);
file.add(exit);
//Listeners
open.addActionListener(new OpenListener(panelBackground, panelwork, panelbtns, p, txt, f));
New.addActionListener(new NewListener(panelBackground, panelwork, panelbtns, p, txt, f));
save.addActionListener(new SaveListener(panelBackground, panelwork, panelbtns, p, txt, f));
Find.addActionListener(new FindListener(panelBackground, panelwork, panelbtns, p, txt, f));
Findrep.addActionListener(new FindAndReplaceListener(panelBackground, panelwork, panelbtns, p, txt, f));
chcol.addActionListener(new ChangeColorListener(panelBackground, panelwork, panelbtns, p, txt, f));
chfont.addActionListener(new ChangeFontListener(panelBackground, panelwork, panelbtns, p, txt, f));
rename.addActionListener((new renameListener(panelBackground, panelwork, panelbtns, p, txt, f)));
exit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
}
}
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class NewListener implements ActionListener {
Panel panelBackground;
Panel panelwork;
Panel panelbtns;
Panel p;
TextArea txt;
Frame f;
public NewListener(Panel panelBackground, Panel panelwork, Panel panelbtns, Panel p, TextArea txt, Frame f) {
this.panelBackground = panelBackground;
this.panelwork = panelwork;
this.panelbtns = panelbtns;
this.p = p;
this.f = f;
this.txt = txt;
}
public void actionPerformed(ActionEvent e) {
txt.setBounds(450, 0, 1000, 650);
panelwork.add(txt);
panelbtns.removeAll();
// making the new Buttons
Button Find = new Button("Find");
Button fRep = new Button("Find and Replace");
Button save = new Button("Save");
Button chcolor = new Button("Change Color");
Button chfont = new Button("Change Font / Font Size");
// adding the new Buttons
panelbtns.add(Find);
panelbtns.add(fRep);
panelbtns.add(save);
panelbtns.add(chcolor);
panelbtns.add(chfont);
//add Listeners
Find.addActionListener(new FindListener(panelBackground, panelwork, panelbtns, p, txt, f));
fRep.addActionListener(new FindAndReplaceListener(panelBackground, panelwork, panelbtns, p, txt, f));
chcolor.addActionListener(new ChangeColorListener(panelBackground, panelwork, panelbtns, p, txt, f));
chfont.addActionListener(new ChangeFontListener(panelBackground, panelwork, panelbtns, p, txt, f));
save.addActionListener(new SaveListener(panelBackground, panelwork, panelbtns, p, txt, f));
panelBackground.add(panelwork, BorderLayout.CENTER);
panelBackground.add(p, BorderLayout.EAST);
// panelBackground.add(p, BorderLayout.WEST);
}
}
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class OpenListener implements ActionListener {
Panel panelBackground;
Panel panelwork;
Panel panelbtns;
Panel p;
TextArea txt;
Frame f;
public OpenListener(Panel panelBackground, Panel panelwork, Panel panelbtns, Panel p, TextArea txt, Frame f) {
this.panelBackground = panelBackground;
this.panelwork = panelwork;
this.panelbtns = panelbtns;
this.p = p;
this.f = f;
this.txt = txt;
}
public void actionPerformed(ActionEvent e) {
System.out.println("Open actioned");
FileDialog fileDialog = new FileDialog(f);
fileDialog.setVisible(true);
String nomFichier = fileDialog.getFile();
String repFichier = fileDialog.getDirectory();
String nomComplet = repFichier + nomFichier;
File file = new File(nomComplet);
int size = (int) file.length();
try {
FileInputStream in = new FileInputStream(file);
byte[] data = new byte[size];
in.read(data);
String str = new String(data);
txt.setText(str);
} catch (FileNotFoundException e2) {
System.out.println(e2);
} catch (IOException e1) {
e1.printStackTrace();
}
txt.setBounds(450, 0, 1000, 650);
panelwork.add(txt);
panelbtns.removeAll();
// making the new Buttons
Button Find = new Button("Find");
Button fRep = new Button("Find and Replace");
Button save = new Button("Save");
Button rename = new Button("Rename");
Button chcolor = new Button("Change Color");
Button chfont = new Button("Change Font / Font Size");
// adding the new Buttons
panelbtns.add(Find);
panelbtns.add(fRep);
panelbtns.add(save);
panelbtns.add(rename);
panelbtns.add(chcolor);
panelbtns.add(chfont);
//add Listeners
Find.addActionListener(new FindListener(panelBackground, panelwork, panelbtns, p, txt, f));
fRep.addActionListener(new FindAndReplaceListener(panelBackground, panelwork, panelbtns, p, txt, f));
chcolor.addActionListener(new ChangeColorListener(panelBackground, panelwork, panelbtns, p, txt, f));
chfont.addActionListener(new ChangeFontListener(panelBackground, panelwork, panelbtns, p, txt, f));
save.addActionListener(new SaveListener(panelBackground, panelwork, panelbtns, p, txt, f));
rename.addActionListener((new renameListener(panelBackground, panelwork, panelbtns, p, txt, f)));
panelBackground.add(panelwork, BorderLayout.CENTER);
panelBackground.add(p, BorderLayout.EAST);
// panelBackground.add(p, BorderLayout.WEST);
}
}
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
public class renameListener implements ActionListener {
Panel panelBackground;
Panel panelwork;
Panel panelbtns;
Panel p;
TextArea txt;
Frame f;
public renameListener(Panel panelBackground, Panel panelwork, Panel panelbtns, Panel p, TextArea txt, Frame f) {
this.panelBackground = panelBackground;
this.panelwork = panelwork;
this.panelbtns = panelbtns;
this.p = p;
this.f = f;
this.txt = txt;
}
public void actionPerformed(ActionEvent e) {
System.out.println("Open actioned");
FileDialog fileDialog = new FileDialog(f);
fileDialog.setVisible(true);
String nomFichier = fileDialog.getFile();
String repFichier = fileDialog.getDirectory();
String nomComplet = repFichier + nomFichier;
File file = new File(nomComplet);
Frame fr = new Frame("Color Name");
fr.setBounds(355, 355, 355, 200);
fr.setLayout(new GridLayout(3, 1));
Label lb = new Label("enter new Name");
TextField newName = new TextField();
Button submit = new Button("Submit");
fr.add(lb);
fr.add(newName);
fr.add(submit);
fr.setVisible(true);
//submit Action
submit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
File fileNew = new File(repFichier + newName.getText());
file.renameTo(fileNew);
fr.setVisible(false);
}
});
}
}
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
public class SaveListener implements ActionListener {
Panel panelBackground;
Panel panelwork;
Panel panelbtns;
Panel p;
TextArea txt;
Frame f;
public SaveListener(Panel panelBackground, Panel panelwork, Panel panelbtns, Panel p, TextArea txt, Frame f) {
this.panelBackground = panelBackground;
this.panelwork = panelwork;
this.panelbtns = panelbtns;
this.p = p;
this.f = f;
this.txt = txt;
}
public void actionPerformed(ActionEvent e) {
FileDialog fd = new FileDialog(f, "Save", FileDialog.SAVE);
fd.setVisible(true);
String file = fd.getFile();
String Dir = fd.getDirectory();
try {
System.out.println(txt.getText());
BufferedWriter bf = new BufferedWriter(new FileWriter(Dir + file));
bf.write(txt.getText());
bf.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
public class WordApp {
public static void main(String[] args) {
MyFrame f = new MyFrame();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment