Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package javaapplication5;
- import java.awt.GridBagConstraints;
- import java.awt.GridBagLayout;
- import java.awt.Insets;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.*;
- public class javaaplication5 extends JFrame{
- public class ObslugaPrzycisku implements ActionListener{
- private JFrame ref_okno;
- ObslugaPrzycisku(JFrame okno){
- ref_okno = okno;
- }
- boolean start;
- boolean error=false;
- double omega;
- double omega_duza;
- double masa;
- double dlugosc;
- double wspolczynnik_tarcia;
- double moment_napedowy;
- double amplituda;
- double okres;
- double omega_rad = Math.toRadians(omega);
- double omega2_rad = Math.toRadians(omega_duza);
- public void actionPerformed(ActionEvent e) {
- JButton bt = (JButton)e.getSource();
- if(bt==przycisk[0])
- start=true;
- if(bt==przycisk[1])
- start=false;
- try {masa=Double.parseDouble(tekst[0].getText());}
- catch (NumberFormatException evt) {
- JOptionPane.showMessageDialog(ref_okno, "masa musi być wartością liczbową");
- error= true;
- tekst[0].setText("10");
- }
- if(masa<0 || masa > 100 ){
- error=true;
- JOptionPane.showMessageDialog(ref_okno, "masa musi byc z przedzialu <0;100>");
- tekst[0].setText("10");
- }
- try {dlugosc=Double.parseDouble(tekst[1].getText());}
- catch (NumberFormatException evt) {
- JOptionPane.showMessageDialog(ref_okno, "długość musi być wartością liczbową");
- error= true;
- tekst[1].setText("10");
- }
- if(dlugosc<0 || dlugosc > 20){ // ustawic dlugosc mase itp;
- error=true;
- JOptionPane.showMessageDialog(ref_okno, "dlugosc musi byc z przedzialu <0;20>");
- tekst[1].setText("10");
- }
- try {wspolczynnik_tarcia=Double.parseDouble(tekst[2].getText());}
- catch (NumberFormatException evt) {
- JOptionPane.showMessageDialog(ref_okno, "wspolczynnik tarcia musi być wartością liczbową");
- error= true;
- tekst[2].setText("10");
- }
- if(wspolczynnik_tarcia<0 || wspolczynnik_tarcia > 100){
- error=true;
- JOptionPane.showMessageDialog(ref_okno, "wspolczynnik_tarcia musi byc z przedzialu <0;100>");
- tekst[2].setText("10");
- }
- try {omega=Double.parseDouble(tekst[5].getText());}
- catch (NumberFormatException evt) {
- JOptionPane.showMessageDialog(ref_okno, "omega musi być wartością liczbową");
- error= true;
- tekst[5].setText("10");
- }
- if(omega<0 || omega > 90){
- error=true;
- JOptionPane.showMessageDialog(ref_okno, "omega musi byc z przedzialu <0;90>");
- tekst[5].setText("10");
- }
- try {amplituda=Double.parseDouble(tekst[4].getText());}
- catch (NumberFormatException evt) {
- JOptionPane.showMessageDialog(ref_okno, "amplituda musi być wartością liczbową");
- error= true;
- tekst[4].setText("10");
- }
- if(amplituda<0 || amplituda > 100){
- error=true;
- JOptionPane.showMessageDialog(ref_okno, "amplituda musi byc z przedzialu <0;100>");
- tekst[4].setText("10");
- }
- try {okres=Double.parseDouble(tekst[3].getText());}
- catch (NumberFormatException evt) {
- JOptionPane.showMessageDialog(ref_okno, "okres musi być wartością liczbową");
- error= true;
- tekst[3].setText("10");
- }
- if(okres<0 || okres > 20){
- error=true;
- JOptionPane.showMessageDialog(ref_okno, "okres musi byc z przedzialu <0;20>");
- tekst[3].setText("10");
- }
- try {omega_duza=Double.parseDouble(tekst[6].getText());}
- catch (NumberFormatException evt) {
- JOptionPane.showMessageDialog(ref_okno, "Prędkość kątowa musi być wartością liczbową");
- error= true;
- tekst[6].setText("10");
- }
- if(omega_duza<0 || omega_duza > 100){
- error=true;
- JOptionPane.showMessageDialog(ref_okno, "Prędkość kątowa musi byc z przedzialu <0;100>");
- tekst[6].setText("10");
- }
- }
- public void obliczenia (){
- double g=9.80665;
- double h=0.01;
- double omega2=omega2_rad;
- double omega1=omega_rad;
- double f=0;
- double f1=0;
- while(start==true)
- {
- f=omega2_rad*h;
- f1=3*h*(-moment_napedowy-wspolczynnik_tarcia*omega2_rad+0.5*dlugosc*masa*g*Math.sin(omega_rad))/(masa*Math.pow(dlugosc, 2));
- omega1 =omega_rad + f;
- omega2 = omega2_rad + f1;
- }
- }
- }
- public static void main(String[] args) {
- new javaaplication5();
- }
- private final JTextField tekst[];
- private JLabel pola[];
- private JRadioButton sygnal[];
- private JButton przycisk[];
- public javaaplication5(){
- pola = new JLabel[7];
- tekst = new JTextField[7];
- sygnal = new JRadioButton[3];
- przycisk = new JButton[2];
- this.setSize(800,800);
- this.setLayout(new GridBagLayout());
- GridBagConstraints frameLayout = new GridBagConstraints();
- frameLayout.anchor = GridBagConstraints.NORTH;
- frameLayout.gridx = 0;
- frameLayout.gridy = 0;
- frameLayout.weightx = 1;
- frameLayout.weighty = 1;
- this.setTitle("Ramka");
- this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- JPanel thePanel = new JPanel(new GridBagLayout());
- thePanel.setLayout(new GridBagLayout());
- GridBagConstraints layout = new GridBagConstraints();
- pola[0] = new JLabel("Masa [kg]:");
- pola[1] = new JLabel("Długość wahadła [m]:");
- pola[2] = new JLabel("Współczynnik tarcia lepkiego [Ns/m]:");
- pola[5] = new JLabel("Odchylenie wahadła [rad]");
- pola[4] = new JLabel("Amplituda sygnału [Nm] :");
- pola[3] = new JLabel("Okres sygnału [s] :");
- pola[6] = new JLabel("Prędkość kątowa [rad/s}: ");
- tekst[0] = new JTextField("10", 5);
- tekst[1] = new JTextField("10", 5);
- tekst[2] = new JTextField("10", 5);
- tekst[3] = new JTextField("10", 5);
- tekst[4] = new JTextField("10", 5);
- tekst[5] = new JTextField("10", 5);
- tekst[6] = new JTextField("10", 5);
- for(int i=0; i<4; i++)
- tekst[i].addActionListener(new ObslugaPrzycisku(this));
- przycisk[0] = new JButton("Start");
- przycisk[1] = new JButton("Stop");
- for(int i=0; i<2; i++)
- przycisk[i].addActionListener(new ObslugaPrzycisku(this));
- sygnal[0] = new JRadioButton("Sygnał Prostokątny");
- sygnal[1] = new JRadioButton("Sygnał Trójkątny");
- sygnal[2] = new JRadioButton("Sygnał Harmoniczny");
- sygnal[0].setSelected(true);
- for(int i=0; i<3; i++)
- sygnal[i].addActionListener(new ObslugaPrzycisku(this));
- layout.fill = GridBagConstraints.BOTH;
- layout.anchor = GridBagConstraints.FIRST_LINE_START;
- layout.insets = new Insets(5,5,5,5);
- layout.gridx = 0;
- layout.gridy = 0;
- for(JLabel l : pola)
- {
- thePanel.add(l, layout);
- layout.gridy += 1;
- }
- layout.gridx = 1;
- layout.gridy = 0;
- for(JTextField t : tekst)
- {
- thePanel.add(t, layout);
- layout.gridy += 1;
- }
- layout.gridx = 2;
- layout.gridy = 0;
- for(JRadioButton rb : sygnal)
- {
- thePanel.add(rb, layout);
- layout.gridy +=1;
- }
- layout.gridx = 3;
- layout.gridy = 0;
- for(JButton b : przycisk)
- {
- thePanel.add(b, layout);
- layout.gridy +=1;
- }
- ButtonGroup group = new ButtonGroup();
- for(int i =0; i<3; i++)
- group.add(sygnal[i]);
- this.add(thePanel, frameLayout);
- this.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement