Commit 97d95b6a authored by mahdikarami0111's avatar mahdikarami0111

initial commit

parents
Pipeline #5991 failed with stages
# Default ignored files
/shelf/
/workspace.xml
<component name="ArtifactManager">
<artifact type="jar" name="APW_S7:jar">
<output-path>$PROJECT_DIR$</output-path>
<root id="archive" name="APW_S7.jar">
<element id="module-output" name="APW_S7" />
</root>
</artifact>
</component>
\ No newline at end of file
<html>Simple <b>Java</b> application that includes a class with <code>main()</code> method</html>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="PROJECT" charset="UTF-8" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EntryPointsManager">
<entry_points version="2.0" />
</component>
<component name="ProjectKey">
<option name="state" value="project://e2804f05-5315-4fc6-a121-c522a6c26470" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_15" default="true" project-jdk-name="15" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/APW_S7.iml" filepath="$PROJECT_DIR$/APW_S7.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<template>
<input-field default="com.company">IJ_BASE_PACKAGE</input-field>
</template>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>
\ No newline at end of file
<?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>
\ No newline at end of file
n1
this is n1
n2
this is n2
n3
this is n3
Manifest-Version: 1.0
Main-Class: com.company.Main
package com.company;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
public class Main {
public static void main(String[] args) {
// ObjectNotes on = new ObjectNotes();
// on.printNotes();
// on.addNote(new Note("n4","n4"));
// on.printNotes();
// on.removeNote(1);
// on.printNotes();
NoteReader nr = new NoteReader();
nr.printNotes();
nr.addNoteBuffer("n4","this is n4");
nr.printNotes();
nr.addNoteBuffer("n5","this is n5");
nr.printNotes();
}
}
package com.company;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
/**
* keeps note and its data
*/
public class Note implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
private String title;
private String body;
private Date date;
/**
* cosntructor of the class sets fields and date
* @param title String title of the note
* @param body String body of the note
*/
public Note(String title, String body) {
this.title = title;
this.body = body;
this.date = new Date();
}
@Override
public String toString(){
return ""+title+"\n"+body+"\n"+date.toString()+"\n";
}
}
package com.company;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
/**
* a class to read and write notes and save them
*/
public class NoteReader {
private ArrayList<String> titles;
private ArrayList<String> bodies;
/**
* constructor for the class allocates memory and reads notes
*/
public NoteReader(){
titles = new ArrayList<>();
bodies = new ArrayList<>();
readNotesFile();
// readNotesBuffer();
}
/**
* reads notes using buffer reader
*/
public void readNotesBuffer(){
titles.clear();
bodies.clear();
FileReader fr = null;
try {
fr = new FileReader("notes.txt");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
BufferedReader br = new BufferedReader(fr);
String title;
try {
while ((title = br.readLine()) != null){
titles.add(title);
bodies.add(br.readLine());
}
br.close();
fr.close();
}catch (IOException e){
e.printStackTrace();
}
}
/**
* adds a note using bufferwriter
* @param title String title of the note
* @param body String body of the note
*/
public void addNoteBuffer(String title,String body){
titles.add(title);
bodies.add(body);
FileWriter fw = null;
try {
fw = new FileWriter("notes.txt");
} catch (IOException e) {
e.printStackTrace();
}
BufferedWriter bw = new BufferedWriter(fw);
for(int i = 0;i<titles.size();i++){
try {
bw.write(titles.get(i)+"\n");
bw.write(bodies.get(i)+"\n");
} catch (IOException e) {
e.printStackTrace();
}
}
try {
bw.close();
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* reads the notes using file stream
*/
public void readNotesFile(){
FileInputStream fi = null;
try {
fi = new FileInputStream("notes.txt");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
int x;
StringBuffer title = new StringBuffer();
StringBuffer body = new StringBuffer();
try {
while ((x = fi.read()) != -1){
title.delete(0,title.length());
body.delete(0,body.length());
title.append((char) x);
while ((x = fi.read()) != '\n'){
title.append((char) x);
}
while ((x = fi.read()) != '\n'){
body.append((char) x);
}
titles.add(title.toString());
bodies.add(body.toString());
}
fi.close();
}catch (IOException e){
e.printStackTrace();
}
}
/**
* adds a new note usng file stream
* @param title String title of the note
* @param body String body of the note
*/
public void addNoteFile(String title,String body){
titles.add(title);
bodies.add(body);
FileOutputStream fo = null;
try {
fo = new FileOutputStream("notes.txt");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
byte[] b;
for(int i = 0;i<titles.size();i++){
b = (titles.get(i)+"\n").getBytes();
fo.write(b);
b = (bodies.get(i)+"\n").getBytes();
fo.write(b);
}
fo.close();
}catch (IOException e){
e.printStackTrace();
}
}
/**
* prints all notes
*/
public void printNotes(){
int i;
for(i=0;i<titles.size();i++){
System.out.println(titles.get(i));
System.out.println(bodies.get(i));
}
System.out.println();
}
}
package com.company;
import java.io.*;
import java.util.ArrayList;
/**
* reads and writes notes as objects
*/
public class ObjectNotes {
private ArrayList<Note> notes;
/**
* constructor of the class allocates memory
*/
public ObjectNotes(){
notes = new ArrayList<>();
}
/**
* reads the notes from the file
*/
public void readNotes(){
notes.clear();
try {
FileInputStream fo = new FileInputStream("notes.bin");
ObjectInputStream o = new ObjectInputStream(fo);
while (true){
try {
notes.add((Note)o.readObject());
}catch (EOFException e){
o.close();
fo.close();
return;
}
}
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
}
/**
* adds a new note
* @param note Note ne note to be added
*/
public void addNote(Note note){
readNotes();
notes.add(note);
try {
FileOutputStream f = new FileOutputStream("notes.bin");
ObjectOutputStream o = new ObjectOutputStream(f);
for (Note n : notes){
o.writeObject(n);
}
o.close();
f.close();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* removes an existing note
* @param index int index of the note to be removed
*/
public void removeNote(int index){
readNotes();
notes.remove(index);
try {
FileOutputStream f = new FileOutputStream("notes.bin");
ObjectOutputStream o = new ObjectOutputStream(f);
for (Note n : notes){
o.writeObject(n);
}
o.close();
f.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public ArrayList<Note> getNotes(){
readNotes();
return notes;
}
/**
* prints all notes
*/
public void printNotes(){
readNotes();
for(Note n : notes){
System.out.print(n);
}
System.out.println();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment