Advertisement
Guest User

Untitled

a guest
May 24th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.98 KB | None | 0 0
  1. package javaapplication5;
  2.  
  3. import java.awt.GridBagConstraints;
  4. import java.awt.GridBagLayout;
  5. import java.awt.Insets;
  6. import java.awt.event.ActionEvent;
  7. import java.awt.event.ActionListener;
  8. import javax.swing.*;
  9.  
  10. public class javaaplication5 extends JFrame{
  11.  
  12. public class ObslugaPrzycisku implements ActionListener{
  13.  
  14. private JFrame ref_okno;
  15.  
  16. ObslugaPrzycisku(JFrame okno){
  17. ref_okno = okno;
  18. }
  19.  
  20. boolean start;
  21. boolean error=false;
  22. double omega;
  23. double omega_duza;
  24. double masa;
  25. double dlugosc;
  26. double wspolczynnik_tarcia;
  27. double moment_napedowy;
  28. double amplituda;
  29. double okres;
  30. double omega_rad = Math.toRadians(omega);
  31. double omega2_rad = Math.toRadians(omega_duza);
  32.  
  33.  
  34. public void actionPerformed(ActionEvent e) {
  35.  
  36. JButton bt = (JButton)e.getSource();
  37.  
  38. if(bt==przycisk[0])
  39. start=true;
  40. if(bt==przycisk[1])
  41. start=false;
  42.  
  43. try {masa=Double.parseDouble(tekst[0].getText());}
  44. catch (NumberFormatException evt) {
  45. JOptionPane.showMessageDialog(ref_okno, "masa musi być wartością liczbową");
  46. error= true;
  47. tekst[0].setText("10");
  48. }
  49. if(masa<0 || masa > 100 ){
  50. error=true;
  51. JOptionPane.showMessageDialog(ref_okno, "masa musi byc z przedzialu <0;100>");
  52. tekst[0].setText("10");
  53. }
  54.  
  55. try {dlugosc=Double.parseDouble(tekst[1].getText());}
  56. catch (NumberFormatException evt) {
  57. JOptionPane.showMessageDialog(ref_okno, "długość musi być wartością liczbową");
  58. error= true;
  59. tekst[1].setText("10");
  60. }
  61. if(dlugosc<0 || dlugosc > 20){ // ustawic dlugosc mase itp;
  62. error=true;
  63. JOptionPane.showMessageDialog(ref_okno, "dlugosc musi byc z przedzialu <0;20>");
  64. tekst[1].setText("10");
  65. }
  66.  
  67. try {wspolczynnik_tarcia=Double.parseDouble(tekst[2].getText());}
  68. catch (NumberFormatException evt) {
  69. JOptionPane.showMessageDialog(ref_okno, "wspolczynnik tarcia musi być wartością liczbową");
  70. error= true;
  71. tekst[2].setText("10");
  72. }
  73. if(wspolczynnik_tarcia<0 || wspolczynnik_tarcia > 100){
  74. error=true;
  75. JOptionPane.showMessageDialog(ref_okno, "wspolczynnik_tarcia musi byc z przedzialu <0;100>");
  76. tekst[2].setText("10");
  77. }
  78.  
  79. try {omega=Double.parseDouble(tekst[5].getText());}
  80. catch (NumberFormatException evt) {
  81. JOptionPane.showMessageDialog(ref_okno, "omega musi być wartością liczbową");
  82. error= true;
  83. tekst[5].setText("10");
  84. }
  85. if(omega<0 || omega > 90){
  86. error=true;
  87. JOptionPane.showMessageDialog(ref_okno, "omega musi byc z przedzialu <0;90>");
  88. tekst[5].setText("10");
  89. }
  90.  
  91. try {amplituda=Double.parseDouble(tekst[4].getText());}
  92. catch (NumberFormatException evt) {
  93. JOptionPane.showMessageDialog(ref_okno, "amplituda musi być wartością liczbową");
  94. error= true;
  95. tekst[4].setText("10");
  96. }
  97. if(amplituda<0 || amplituda > 100){
  98. error=true;
  99. JOptionPane.showMessageDialog(ref_okno, "amplituda musi byc z przedzialu <0;100>");
  100. tekst[4].setText("10");
  101. }
  102.  
  103. try {okres=Double.parseDouble(tekst[3].getText());}
  104. catch (NumberFormatException evt) {
  105. JOptionPane.showMessageDialog(ref_okno, "okres musi być wartością liczbową");
  106. error= true;
  107. tekst[3].setText("10");
  108. }
  109. if(okres<0 || okres > 20){
  110. error=true;
  111. JOptionPane.showMessageDialog(ref_okno, "okres musi byc z przedzialu <0;20>");
  112. tekst[3].setText("10");
  113. }
  114.  
  115. try {omega_duza=Double.parseDouble(tekst[6].getText());}
  116. catch (NumberFormatException evt) {
  117. JOptionPane.showMessageDialog(ref_okno, "Prędkość kątowa musi być wartością liczbową");
  118. error= true;
  119. tekst[6].setText("10");
  120. }
  121. if(omega_duza<0 || omega_duza > 100){
  122. error=true;
  123. JOptionPane.showMessageDialog(ref_okno, "Prędkość kątowa musi byc z przedzialu <0;100>");
  124. tekst[6].setText("10");
  125. }
  126.  
  127. }
  128.  
  129.  
  130. public void obliczenia (){
  131.  
  132. double g=9.80665;
  133. double h=0.01;
  134. double omega2=omega2_rad;
  135. double omega1=omega_rad;
  136. double f=0;
  137. double f1=0;
  138.  
  139. while(start==true)
  140. {
  141. f=omega2_rad*h;
  142. f1=3*h*(-moment_napedowy-wspolczynnik_tarcia*omega2_rad+0.5*dlugosc*masa*g*Math.sin(omega_rad))/(masa*Math.pow(dlugosc, 2));
  143. omega1 =omega_rad + f;
  144. omega2 = omega2_rad + f1;
  145. }
  146.  
  147.  
  148.  
  149.  
  150. }
  151.  
  152. }
  153. public static void main(String[] args) {
  154.  
  155. new javaaplication5();
  156.  
  157. }
  158.  
  159. private final JTextField tekst[];
  160. private JLabel pola[];
  161. private JRadioButton sygnal[];
  162. private JButton przycisk[];
  163.  
  164. public javaaplication5(){
  165.  
  166. pola = new JLabel[7];
  167. tekst = new JTextField[7];
  168. sygnal = new JRadioButton[3];
  169. przycisk = new JButton[2];
  170.  
  171. this.setSize(800,800);
  172.  
  173. this.setLayout(new GridBagLayout());
  174. GridBagConstraints frameLayout = new GridBagConstraints();
  175. frameLayout.anchor = GridBagConstraints.NORTH;
  176. frameLayout.gridx = 0;
  177. frameLayout.gridy = 0;
  178. frameLayout.weightx = 1;
  179. frameLayout.weighty = 1;
  180.  
  181. this.setTitle("Ramka");
  182.  
  183. this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  184.  
  185. JPanel thePanel = new JPanel(new GridBagLayout());
  186. thePanel.setLayout(new GridBagLayout());
  187. GridBagConstraints layout = new GridBagConstraints();
  188.  
  189. pola[0] = new JLabel("Masa [kg]:");
  190. pola[1] = new JLabel("Długość wahadła [m]:");
  191. pola[2] = new JLabel("Współczynnik tarcia lepkiego [Ns/m]:");
  192. pola[5] = new JLabel("Odchylenie wahadła [rad]");
  193. pola[4] = new JLabel("Amplituda sygnału [Nm] :");
  194. pola[3] = new JLabel("Okres sygnału [s] :");
  195. pola[6] = new JLabel("Prędkość kątowa [rad/s}: ");
  196.  
  197. tekst[0] = new JTextField("10", 5);
  198. tekst[1] = new JTextField("10", 5);
  199. tekst[2] = new JTextField("10", 5);
  200. tekst[3] = new JTextField("10", 5);
  201. tekst[4] = new JTextField("10", 5);
  202. tekst[5] = new JTextField("10", 5);
  203. tekst[6] = new JTextField("10", 5);
  204.  
  205.  
  206. for(int i=0; i<4; i++)
  207. tekst[i].addActionListener(new ObslugaPrzycisku(this));
  208.  
  209. przycisk[0] = new JButton("Start");
  210. przycisk[1] = new JButton("Stop");
  211.  
  212. for(int i=0; i<2; i++)
  213. przycisk[i].addActionListener(new ObslugaPrzycisku(this));
  214.  
  215. sygnal[0] = new JRadioButton("Sygnał Prostokątny");
  216. sygnal[1] = new JRadioButton("Sygnał Trójkątny");
  217. sygnal[2] = new JRadioButton("Sygnał Harmoniczny");
  218.  
  219. sygnal[0].setSelected(true);
  220.  
  221. for(int i=0; i<3; i++)
  222. sygnal[i].addActionListener(new ObslugaPrzycisku(this));
  223.  
  224. layout.fill = GridBagConstraints.BOTH;
  225. layout.anchor = GridBagConstraints.FIRST_LINE_START;
  226. layout.insets = new Insets(5,5,5,5);
  227.  
  228. layout.gridx = 0;
  229. layout.gridy = 0;
  230. for(JLabel l : pola)
  231. {
  232. thePanel.add(l, layout);
  233. layout.gridy += 1;
  234. }
  235.  
  236. layout.gridx = 1;
  237. layout.gridy = 0;
  238. for(JTextField t : tekst)
  239. {
  240. thePanel.add(t, layout);
  241. layout.gridy += 1;
  242. }
  243.  
  244. layout.gridx = 2;
  245. layout.gridy = 0;
  246. for(JRadioButton rb : sygnal)
  247. {
  248. thePanel.add(rb, layout);
  249. layout.gridy +=1;
  250. }
  251.  
  252. layout.gridx = 3;
  253. layout.gridy = 0;
  254. for(JButton b : przycisk)
  255. {
  256. thePanel.add(b, layout);
  257. layout.gridy +=1;
  258. }
  259.  
  260. ButtonGroup group = new ButtonGroup();
  261. for(int i =0; i<3; i++)
  262. group.add(sygnal[i]);
  263.  
  264. this.add(thePanel, frameLayout);
  265. this.setVisible(true);
  266. }
  267.  
  268.  
  269.  
  270. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement