السلام عليكم الله يسعدكم انا حايسه في دا الكود وابغى احد يفهمني هو الاشيا اللي مو فاهمتها حاطه عليها تعليقات
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Calc extends Frame implements WindowListener,ActionListener {
TextField text1 = new TextField(20);
TextField text2 = new TextField(20);
File file; // هنا ايش يعني دا السطر
int numlines;
Label label1,label2,label3;
Button b1,b2,b3;
private int numClicks = 0; // ايش معنى دا السطر
String arrst[]={"out1.txt","out2.txt","out3.txt","out4.txt","out5.txt","out6.txt","out7.txt"}; //هنا ليه سوينا مصفوفه
String filename;
public static void main(String[] args) {
Calc myWindow = new Calc("File Chopper");
myWindow.setSize(320,150);
myWindow.setVisible(true);
}
public Calc(String title) { //ايش مهنى دا السطر
super(title); // ايش معنى دا السطر وايش فايدة كلمه سوبر
setLayout(new FlowLayout());
addWindowListener(this);//ايش تعني كلمه ذس ايش الفرق بين الويندوز لسينر والاكشن ليسنر وليش نحط كلمه ذس بي الاقواس
label1 = new Label("File Name");
add(label1);
add(text1);
label2 = new Label("Number of lines");
add(label2);
add(text2);
b2 = new Button("RUN");
b3 = new Button("CLOSE");
b1 = new Button("Browse");
add(b2);
add(b3);
add(b1);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand()=="Browse")
{
JFileChooser fileopen = new JFileChooser();//ايش معنى السطر دا
int ret = fileopen.showDialog(null, "Open file"); // ايش معنى السطر دا
if (ret == JFileChooser.APPROVE_OPTION) {//جميع جمله الشرط ايش تعني ياليت تشرحوها سطر سطر
file = fileopen.getSelectedFile();
text1.setText(" "+file.getName());
filename=file.getName().toString();
}
}
else if(e.getActionCommand()=="RUN")
{
String curr=""; //ليش عرفنا متغير من نوع سترنغ هنا ايش الفايده منو
int currnumline=0; // ليش عرفنا المتغير دا
numlines=Integer.parseInt(text2.getText());//ايش دا السطر
int test=0;// ليش عرفنا متغير من نوع انتيجر
int counter=0;//ليش سوينا كونتير
String newline = System.getProperty("line.separator");// ايش معنى دا السطر
try { //شرح جملة التراي كلها
BufferedReader in = new BufferedReader(new FileReader(filename));
String str;
while ((str = in.readLine()) != null) {
currnumline++;
curr+=str;
curr+=newline;
test++;
if(test==numlines) // شرح جملة الشرط كلها
{
FileWriter fstream = new FileWriter(arrst[counter]);
BufferedWriter out = new BufferedWriter(fstream);
out.write(curr);
//Close the output stream
out.close();
curr="";
System.out.print(" ok ");
counter++;
test=0;
}
}// ايش يعني الثلاثه الاسطر اللي تحت
in.close();
} catch (IOException e1) {
System.out.print(e.toString());
}
///////////////////
}
else //شرح جمله ال ايلس
{
dispose();
System.exit(0);
}
}
public void windowClosing(WindowEvent e) { // واخيرا شرح الجمل اللي تحت كلها
dispose();
System.exit(0);
}
public void windowOpened(WindowEvent e) {}
public void windowActivated(WindowEvent e) {}
public void windowIconified(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {}
public void windowDeactivated(WindowEvent e) {}
public void windowClosed(WindowEvent e) {}
}