How to program under linux

Reply

Join Date: May 2009
Posts: 4
Reputation: fuzzyrose is an unknown quantity at this point 
Solved Threads: 0
fuzzyrose fuzzyrose is offline Offline
Newbie Poster

How to program under linux

 
0
  #1
May 20th, 2009
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.

  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4.  
  5. class fcfs extends JFrame implements ActionListener
  6. {
  7. JButton jb[] = new JButton[3];
  8. JTextField jt1[],jt2[];
  9. JLabel jl[],jl1,jl2,jl3;
  10. JPanel jp,jp1;
  11. Container con;
  12. int k,p;
  13. String str[] = {"SUBMIT","RESET","EXIT"};
  14. String str1[] = {"Process"," AT","ST","WT","FT","TAT","NTAT"};
  15.  
  16.  
  17. public fcfs()
  18. {
  19. super("fcfs scheduling algoritham");
  20. con = getContentPane();
  21.  
  22. k= Integer.parseInt(JOptionPane.showInputDialog("Enter number ofprocess"));
  23.  
  24. jl1 = new JLabel("Process");
  25. jl2 = new JLabel("Arival Time");
  26. jl3 = new JLabel("Service Time");
  27.  
  28. jl = new JLabel[k];
  29. jt1 = new JTextField[k];
  30. jt2 = new JTextField[k];
  31.  
  32.  
  33. for(int i=0;i<k;i++)
  34. {
  35. jl[i] = new JLabel("process"+(i+1));
  36. jt1[i] = new JTextField(10);
  37. jt2[i] = new JTextField(10);
  38. }
  39.  
  40. for(int i=0;i<3;i++)
  41. {
  42. jb[i] = new JButton(str[i]);
  43. }
  44.  
  45. con.setLayout(new GridLayout(k+2,3));
  46. con.add(jl1);
  47. con.add(jl2);
  48. con.add(jl3);
  49.  
  50. int l=0;
  51.  
  52. for(int i=0;i<k;i++)
  53. {
  54. con.add(jl[l]);
  55. con.add(jt1[l]);
  56. con.add(jt2[l]);
  57. l++;
  58. }
  59. l=0;
  60. for(int i=0;i<3;i++)
  61. {
  62. con.add(jb[l]);
  63. jb[l].addActionListener(this);
  64. l++;
  65. }
  66. }//end of constructor
  67.  
  68. public void actionPerformed(ActionEvent ae)
  69. {
  70. int FT[] = new int[k];
  71. int WT[] = new int[k];
  72. int TAT[] = new int[k];
  73. float NTAT[] = new float[k];
  74. float sum=0;
  75. float avg;
  76. JPanel main = new JPanel();
  77. main.setLayout(new BorderLayout());
  78. jp = new JPanel();
  79. jp1 = new JPanel();
  80. jp.setLayout(new GridLayout(k+1,7));
  81. jp1.setLayout(new FlowLayout());
  82.  
  83. if(ae.getSource() == jb[2])
  84. {
  85. System.exit(0);
  86. }
  87. else if(ae.getSource() == jb[0])
  88. {
  89. FT[0] = Integer.parseInt(jt1[0].getText()) +
  90. Integer.parseInt(jt2[0].getText());
  91.  
  92. for(int i=0;i<k;i++)
  93. {
  94. if(i==0)
  95. {
  96. WT[i] = 0;
  97. }
  98. else
  99. {
  100. if(FT[i-1] < Integer.parseInt(jt1[i].getText()))
  101. {
  102. FT[i] =
  103. Integer.parseInt(jt1[i].getText())+Integer.parseInt(jt2[i].getText());
  104. WT[i] = 0;
  105. }
  106. else
  107. {
  108. FT[i] = FT[i-1] + Integer.parseInt(jt2[i].getText());
  109. WT[i] = FT[i-1] - Integer.parseInt(jt1[i].getText());
  110. }
  111.  
  112. }
  113. TAT[i] = WT[i]+Integer.parseInt(jt2[i].getText());
  114. NTAT[i] = TAT[i]/(Integer.parseInt(jt2[i].getText()));
  115. sum = sum+WT[i];
  116.  
  117.  
  118. }//end for loop
  119. for (int i=0;i<7;i++ )
  120. {
  121. jp.add(new JLabel(str1[i]));
  122. }
  123. for (int i=0;i<k;i++)
  124. {
  125. jp.add(new JLabel("process"+(i+1)));
  126. jp.add(new JLabel(" "+Integer.parseInt(jt1[i].getText())));
  127. jp.add(new JLabel(""+Integer.parseInt(jt2[i].getText())));
  128. jp.add(new JLabel(""+WT[i]));
  129. jp.add(new JLabel(""+FT[i]));
  130. jp.add(new JLabel(""+TAT[i]));
  131. jp.add(new JLabel(""+NTAT[i]));
  132.  
  133.  
  134. }
  135. avg = sum/k;
  136. String str2 = "Average Waiting Time is "+ avg;
  137. jp1.add(new JLabel(str2));
  138. main.add(jp,BorderLayout.NORTH);
  139. main.add(jp1,BorderLayout.SOUTH);
  140.  
  141. JOptionPane.showMessageDialog(null,main,"output",JOptionPane.PLAIN_MESSAGE
  142. );
  143.  
  144. }
  145. else if(ae.getSource() == jb[1])
  146. {
  147. setVisible(false);
  148. fcfs window = new fcfs();
  149. window.setSize(400,300);
  150. window.setVisible(true);
  151. window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  152.  
  153. }
  154. }//END ACTION PERFORMED
  155.  
  156. public static void main(String[] args)
  157. {
  158. fcfs window = new fcfs();
  159. window.setSize(400,300);
  160. window.setVisible(true);
  161. window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  162. }//end main
  163. }//end class
Last edited by John A; May 20th, 2009 at 9:29 pm. Reason: added code tags, removed color tags
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 686
Reputation: sillyboy is on a distinguished road 
Solved Threads: 61
sillyboy's Avatar
sillyboy sillyboy is offline Offline
Practically a Master Poster

Re: How to program under linux

 
0
  #2
May 20th, 2009
well that is obviously Java, and the code should need to change for linux. next time, you should use code tags around your code.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 972
Reputation: JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice 
Solved Threads: 146
JamesCherrill JamesCherrill is offline Offline
Posting Shark

Re: How to program under linux

 
0
  #3
May 21st, 2009
There's nothing Windows-specific in there, so it should just compile and run under Linux as-is. Have you tried it?
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1,566
Reputation: BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all 
Solved Threads: 196
BestJewSinceJC BestJewSinceJC is offline Offline
Posting Virtuoso

Re: How to program under linux

 
0
  #4
May 21st, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,612
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 463
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: How to program under linux

 
-1
  #5
May 22nd, 2009
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
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 972
Reputation: JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice 
Solved Threads: 146
JamesCherrill JamesCherrill is offline Offline
Posting Shark

Re: How to program under linux

 
0
  #6
May 22nd, 2009
Originally Posted by adatapost View Post
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).
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 823
Reputation: verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough 
Solved Threads: 73
verruckt24's Avatar
verruckt24 verruckt24 is offline Offline
Practically a Posting Shark

Re: How to program under linux

 
0
  #7
May 22nd, 2009
@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 ?
Get up every morning and take a look at the Forbes' list of richest people. If your name doesn't appear.... GET TO WORK !!!
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,612
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 463
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: How to program under linux

 
0
  #8
May 22nd, 2009
Originally Posted by JamesCherrill View Post
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?
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 972
Reputation: JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice 
Solved Threads: 146
JamesCherrill JamesCherrill is offline Offline
Posting Shark

Re: How to program under linux

 
0
  #9
May 22nd, 2009
Originally Posted by adatapost View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,612
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 463
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: How to program under linux

 
0
  #10
May 22nd, 2009
Originally Posted by JamesCherrill View Post
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)
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC