Hi all
I want a help for changing this program to a linux program .
Can anyone help me?
wether is it in c++ or Java.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

class fcfs extends JFrame implements ActionListener
{
JButton jb[] = new JButton[3];
JTextField jt1[],jt2[];
JLabel jl[],jl1,jl2,jl3;
JPanel jp,jp1;
Container con;
int k,p;
String str[] = {"SUBMIT","RESET","EXIT"};
String str1[] = {"Process"," AT","ST","WT","FT","TAT","NTAT"};


public fcfs()
{
super("fcfs scheduling algoritham");
con = getContentPane();

k= Integer.parseInt(JOptionPane.showInputDialog("Enter number ofprocess"));

jl1 = new JLabel("Process");
jl2 = new JLabel("Arival Time");
jl3 = new JLabel("Service Time");

jl = new JLabel[k];
jt1 = new JTextField[k];
jt2 = new JTextField[k];


for(int i=0;i<k;i++)
{
jl[i] = new JLabel("process"+(i+1));
jt1[i] = new JTextField(10);
jt2[i] = new JTextField(10);
}

for(int i=0;i<3;i++)
{
jb[i] = new JButton(str[i]);
}

con.setLayout(new GridLayout(k+2,3));
con.add(jl1);
con.add(jl2);
con.add(jl3);

int l=0;

for(int i=0;i<k;i++)
{
con.add(jl[l]);
con.add(jt1[l]);
con.add(jt2[l]);
l++;
}
l=0;
for(int i=0;i<3;i++)
{
con.add(jb[l]);
jb[l].addActionListener(this);
l++;
}
}//end of constructor

public void actionPerformed(ActionEvent ae)
{
int FT[] = new int[k];
int WT[] = new int[k];
int TAT[] = new int[k];
float NTAT[] = new float[k];
float sum=0;
float avg;
JPanel main = new JPanel();
main.setLayout(new BorderLayout());
jp = new JPanel();
jp1 = new JPanel();
jp.setLayout(new GridLayout(k+1,7));
jp1.setLayout(new FlowLayout());

if(ae.getSource() == jb[2])
{
System.exit(0);
}
else if(ae.getSource() == jb[0])
{
FT[0] = Integer.parseInt(jt1[0].getText()) +
Integer.parseInt(jt2[0].getText());

for(int i=0;i<k;i++)
{
if(i==0)
{
WT[i] = 0;
}
else
{
if(FT[i-1] < Integer.parseInt(jt1[i].getText()))
{
FT[i] =
Integer.parseInt(jt1[i].getText())+Integer.parseInt(jt2[i].getText());
WT[i] = 0;
}
else
{
FT[i] = FT[i-1] + Integer.parseInt(jt2[i].getText());
WT[i] = FT[i-1] - Integer.parseInt(jt1[i].getText());
}

}
TAT[i] = WT[i]+Integer.parseInt(jt2[i].getText());
NTAT[i] = TAT[i]/(Integer.parseInt(jt2[i].getText()));
sum = sum+WT[i];


}//end for loop
for (int i=0;i<7;i++ )
{
jp.add(new JLabel(str1[i]));
}
for (int i=0;i<k;i++)
{
jp.add(new JLabel("process"+(i+1)));
jp.add(new JLabel(" "+Integer.parseInt(jt1[i].getText())));
jp.add(new JLabel(""+Integer.parseInt(jt2[i].getText())));
jp.add(new JLabel(""+WT[i]));
jp.add(new JLabel(""+FT[i]));
jp.add(new JLabel(""+TAT[i]));
jp.add(new JLabel(""+NTAT[i]));


}
avg = sum/k;
String str2 = "Average Waiting Time is "+ avg;
jp1.add(new JLabel(str2));
main.add(jp,BorderLayout.NORTH);
main.add(jp1,BorderLayout.SOUTH);

JOptionPane.showMessageDialog(null,main,"output",JOptionPane.PLAIN_MESSAGE
);

}
else if(ae.getSource() == jb[1])
{
setVisible(false);
fcfs window = new fcfs();
window.setSize(400,300);
window.setVisible(true);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}
}//END ACTION PERFORMED

public static void main(String[] args)
{
fcfs window = new fcfs();
window.setSize(400,300);
window.setVisible(true);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}//end main
}//end class

well that is obviously Java, and the code should need to change for linux. next time, you should use code tags around your code.

There's nothing Windows-specific in there, so it should just compile and run under Linux as-is. Have you tried it?

Linux is an operating system. Java is a programming language. Coincidentally, java should run the same on Windows and Linux (don't count on it) but if this was a C++ program, you would not have the same luck.

Dear FussyRose,

Your program is written for any hardware (because you choose java platform). After all, Java source code needs compilation if you want to change the os.

so, compile your java program and run it on Linux without hesitation.

Good Luck

commented: He has certainly not written it himself. Try thinking before you dole out advice -1

Dear FussyRose,
Java source code needs compilation if you want to change the os.
Good Luck

Not true. Compiled class files and jar files are the same across all OSs. An executable jar created in Windows will run in Linux (provided it contains no Windows-specific code).

@OP : This program isn't written by you isn't it ? Since you do not even know whether it's for C++ or Java. So before I give you an advice, unlike others who I guess haven't put a thought to this, I would like to know the source of this program. Why you would like to change it and Why you are working with something that you even do not know the origin of ?

Not true. Compiled class files and jar files are the same across all OSs. An executable jar created in Windows will run in Linux (provided it contains no Windows-specific code).

adatapost>What happned if different version of jvm is there?

adatapost>What happned if different version of jvm is there?

When you compile java you can specify the minimum version of JVM that it will run on, so if you've compiled for 1.4 it won't run on 1.2 - but that's not an OS issue, it's a Java version issue. If you are referring to non-Sun JVMs then that's an issue of whether they are compatible with Sun's reference implementation or not.
In short - if your compiled code runs on one platform with Sun's JVM, it will run on any other platform's Sun JVM that is sufficiently recent.

When you compile java you can specify the minimum version of JVM that it will run on, so if you've compiled for 1.4 it won't run on 1.2 - but that's not an OS issue, it's a Java version issue. If you are referring to non-Sun JVMs then that's an issue of whether they are compatible with Sun's reference implementation or not.
In short - if your compiled code runs on one platform with Sun's JVM, it will run on any other platform's Sun JVM that is sufficiently recent.

adatapost>That means for the purpose of safe & confirm execution, a source code file should be compiled on destination hardware. (may be a destination machine has older verion of jvm)

No, I think you missed my point. You only have to compile Java for a minimum JVM version. The resulting class files will run on any "destination hardware" that has a JVM of that version or later.
If you have access to Windows and Linux you can very easily confirm this for yourself.

Thanx for all of you.
verruckt24 :I know it is java program and I tried to compile it in linux but it didn't work.
the reason why I want to change it is to try linux programming.

There is no such thing as linux programming. Linux is an Operating System, not a programming language. As far as I know, the Linux operating system kernel is written in the C programming language.

:I know it is java program

Don't lie to our faces we would screw you for that.

wether is it in c++ or Java.

I tried to compile it in linux but it didn't work.

And don't give lame excuses either; You haven't written this piece of code and you had no idea about it whatsoever, till the forum members told you about it, and thats a fact. Asking for help isn't a bad thing but lying in somebody's face and picking up code not written by you certainly is.

I tried to compile it in linux but it didn't work.

If it didn't work, why didn't you post the errors you were getting in first place?

fuzyrose: Lots of confusion here. People are trying to help you, but you don't seem to know what help you need.
If you want to learn about programming specifically for Linux, then forget Java. The whole point about Java is that it is cross-platform; Java programming in Linux is exactly the same as Java programming under Windows (etc).
To get Linux-specific skills you need to be working in C or one of its derivatives where you will be calling the system libraries and common utilities directly.

Well I think you misunderstand me guys!
I didn't lie at all cause I didn't say that I write the program
yes I didn't write it and I asked to help me how to compile the program in linux
only the way like steps do 1,2,3,... thats it?
I will say it again I know it is a java program I'm not that stupid to not know it is c++ or java?
Also,I'm only in my second grade at the college and I want to know how to compile a program in linux (Operating System) ????????????

I know it is a java program I'm not that stupid to not know it is c++ or java?

Yes you are, if not what do you make of this statement.

wether is it in c++ or Java.

Don't try giving excuses for what you have done especially lying, accept what you did and move on. The more you say I ain't stupid, I ain't dumb the more I will prove that you are. You cannot counter hard proof with lame excuses.

As far as the compiling and understanding help required part goes, I have already mentioned that's not a problem, this forum exists for that very reason.

Also,I'm only in my second grade at the college and I want to know how to compile a program in linux (Operating System)

Java programs would be compiled the same way that they are compiled on a Windows platform. If you have a Java SDK installed you need to run the command:
javac filename.java to compile a file; then
java filename to run the file.

adatapost>You are in very aggressive mood. Cool down verruckt24.

Why not the Sun's JDK ?

No special reason, syntax is the same, but I though this particular web site gives all the info OP could possibly need to compile "his"program.

adatapost>You are in very aggressive mood. Cool down verruckt24.

No I am not. But I don't think I or anyone for that matter can stand somebody lying into his/her face. You might feel the way you are feeling and I can understand someone feeling that way, but my mood is in fact quite in contrast to that, that is the reason I said, "accept what you did and move on" it's not like that we are going to shoot him for that. But keeping on repeating that he was knowing it, when the fact was that he wasn't isn't a thing that could go down well with the members here, or atleast me for certain.

Admitting to a one's mistake is the first step in correcting it, or atleast avoiding oneself from repeating it.

As far as your concern goes, I am in a good mood really, see I am laughing too :)

:icon_smile: That's the Great man's style.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.