08
Июл
2017

вывод значений на экран через GUI Java

я мало что понимаю в java, поэтому я не могу сделать вывод результатов вычислений на экран. как можно это сделать в данном случае? пока сделать хотя бы по-колхозному, но главное, чтобы я понял.

package example;
import javax.swing.JFrame;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;




public class Main {
public static void main(String [] args)  {
    Windows windows = new Windows("Термодинамические свойства газов 2");
    Vozdyx vozdyx = new Vozdyx();
    Azot azot = new Azot();
    AzotAtm azots = new AzotAtm();
    Kislorod kislorod = new Kislorod();
    DvyokisC dvyokisC = new DvyokisC();
    Voda voda = new Voda();
    OkisC okisC = new OkisC();
    Vodorod vodorod = new Vodorod();

    windows.setVisible(true);
    windows.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    windows.setSize(500, 550);
    windows.setResizable(true);
    windows.setLocationRelativeTo(null);
    windows.setLayout(null);
    windows.l1.setLocation(10,10);
    windows.l2.setLocation(10,30);
    windows.l3.setLocation(10,50);
    windows.l4.setLocation(10,70);
    windows.l5.setLocation(10,90);
    windows.l6.setLocation(10,110);
    windows.l7.setLocation(10,130);
    windows.l8.setLocation(10,150);
    windows.l9.setLocation(10,170);
    windows.l10.setLocation(10,190);

    windows.l11.setLocation(10,210);
    windows.l12.setLocation(10,230);
    windows.l13.setLocation(10,250);
    windows.l14.setLocation(10,270);
    windows.l15.setLocation(10,290);
    windows.l16.setLocation(10,310);
    windows.l17.setLocation(10,330);
    windows.l18.setLocation(10,350);
    windows.l19.setLocation(10,370);
    windows.l20.setLocation(10,390);
    windows.l21.setLocation(10,410);
    windows.l22.setLocation(10,430);
    windows.l23.setLocation(10,450);
    windows.l24.setLocation(10,470);
    windows.l25.setLocation(10,490);

    windows.l26.setLocation(140,215);
    windows.l27.setLocation(140,230);
    windows.l28.setLocation(140,250);
    windows.l29.setLocation(140,270);
    windows.l30.setLocation(140,290);
    windows.l31.setLocation(140,310);
    windows.l32.setLocation(140,330);
    windows.l33.setLocation(140,350);
    windows.l34.setLocation(140,370);
    windows.l35.setLocation(140,390);
    windows.l36.setLocation(140,410);
    windows.l37.setLocation(140,430);
    windows.l38.setLocation(140,450);
    windows.l39.setLocation(140,470);
    windows.l40.setLocation(140,490);



    windows.t1.setLocation(140,170);
    windows.t2.setLocation(140,190);

    windows.b1.setLocation(270,170);


}
}


class Windows extends JFrame{
JButton b1, b2;
JLabel  l1, l2, l3, l4, l5, l6, l7, l8, l9, l10,
 l11, l12, l13, l14, l15, l16, l17, l18, l19, l20,
 l21, l22, l23, l24, l25, l26, l27, l28, l29, l30, 
 l31, l32, l33, l34, l35, l36, l37, l38, l39, l40;
JTextField t1, t2;
Integer z, x;
static double T;
String T1, a;
enter enter = new enter();



public Windows(String s) {
    super (s);
    setLayout(new FlowLayout());

    l1 = new JLabel("1 - Воздух");
    l2 = new JLabel("2 - N2  (Азот)");
    l3 = new JLabel("3 - N2' (Азот атмосферный)");
    l4 = new JLabel("4 - O2  (Кислород)");
    l5 = new JLabel("5 - CO2 (Диоксид углерода");
    l6 = new JLabel("6 - H2O (Водяной пар)");
    l7 = new JLabel("7 - CO  (Оксид углерода)");
    l8 = new JLabel("8 - H2  (Водород) ");
    l9 = new JLabel("Введите номер газа: ");
    l10 = new JLabel("Введите температуру:");

    l11 = new JLabel("t"); 
    l12 = new JLabel("T");
    l13 = new JLabel("Cp"); 
    l14 = new JLabel("MCp");
    l15 = new JLabel("Cv"); 
    l16 = new JLabel("MCv"); 
    l17 = new JLabel("K = Cp/Cv"); 
    l18 = new JLabel("h");
    l19 = new JLabel("u");
    l20 = new JLabel("Pi"); 
    l21 = new JLabel("O"); 
    l22 = new JLabel("S0");
    l23 = new JLabel("H");
    l24 = new JLabel("U");
    l25 = new JLabel("S");  
    l26 = new JLabel("");
    l27 = new JLabel("");
    l28 = new JLabel("");
    l29 = new JLabel("");
    l30 = new JLabel("");
    l31 = new JLabel("");
    l32 = new JLabel("");
    l33 = new JLabel("");
    l34 = new JLabel("");
    l35 = new JLabel("");
    l36 = new JLabel("");
    l37 = new JLabel("");
    l38 = new JLabel("");
    l39 = new JLabel("");
    l40 = new JLabel("");



    b1 = new JButton("посчитать");

    b1.setPreferredSize(new Dimension(100,19));

    b1.addActionListener(enter);

    t1 = new JTextField(10);
    t2 = new JTextField(10);

    add(l1);
    add(l2);
    add(l3);
    add(l4);
    add(l5);
    add(l6);
    add(l7);
    add(l8);
    add(l9);
    add(l10);
    add(l11);
    add(l12);
    add(l13);
    add(l14);
    add(l15);
    add(l16);
    add(l17);
    add(l18);
    add(l19);
    add(l20);
    add(l21);
    add(l22);
    add(l23);
    add(l24);
    add(l25);
    add(l26);
    add(l27);
    add(l28);
    add(l29);
    add(l30);
    add(l31);
    add(l32);
    add(l33);
    add(l34);
    add(l35);
    add(l36);
    add(l37);
    add(l38);
    add(l39);
    add(l40);

    add(t1);
    add(t2);

    add(b1);

}



public class enter implements ActionListener{

    public void actionPerformed(ActionEvent e) {
        try{


            if (e.getSource() == b1) {
                 z = Integer.parseInt(t1.getText());
                 x = Integer.parseInt(t2.getText()); 


                if (z == 1) {Vozdyx.setT(x);  a = x.toString();
                 l26.setText(a);
                 l26.setSize(2500, 10);
                 T1 = "";
                 l27.setText(T1);
                 l27.setSize(2500, 10);}

                if (z == 2) {Azot.setT(x); }

                if (z == 3) {AzotAtm.setT(x);}

                if (z == 4) {Kislorod.setT(x);}

                if (z == 5) {DvyokisC.setT(x);}

                if (z == 6) {Voda.setT(x);}

                if (z == 7) {OkisC.setT(x);}

                if (z == 8) {Vodorod.setT(x);}

                if (z >= 9) {JOptionPane.showMessageDialog(null, "Не правильно указан газ");}

             }                      
        }catch (Exception ex) {JOptionPane.showMessageDialog(null, "Ошибка ввода данных");}

    }

    }
}

class Vozdyx{
private static double T;
public static  void setT (double x){T = (x/1000);}

private static final double M = 28.970;
private static final double R = 8.3144598;
private static final double e = 2.7182818284;
private static final double s0 = 6.6084;
private static final double T0 = 0.034833326785;

private static final double ac = 0;
private static final double ac0 = 29.438265;
private static final double ac1 = -1.6108220;
private static final double ac2 = -11.991744;
private static final double ac3 = 68.828384;
private static final double ac4 = -98.239929;
private static final double ac5 = 64.883505; 
private static final double ac6 = -20.909380; 
private static final double ac7 = 2.6652402;

private static final double ah0 = -542;
private static final double ah1 = 29438.265;
private static final double ah2 = -805.41099;
private static final double ah3 = -3997.2481;
private static final double ah4 = 17207.096;
private static final double ah5 = -19647.986;
private static final double ah6 = 10813.917;
private static final double ah7 = -2987.0543;
private static final double ah8 = 333.15502;
private static final int bh = 0;

private static final double as = 0;
private static final double as0 = 230.1763;
private static final double as1 = -1.610822;
private static final double as2 = -5.9958719;
private static final double as3 = 22.942794;
private static final double as4 = -24.559982;
private static final double as5 = 12.976701;
private static final double as6 = -3.4848967;
private static final double as7 = 0.3807486;
private static final double bs = 29.438205;
double MCpVoz = (ac * Math.pow(T, -1)+ac0 * Math.pow(T, 0)+ac1 * Math.pow(T, 1)+ac2 * Math.pow(T, 2)
+ac3 * Math.pow(T, 3)+ac4 * Math.pow(T, 4)+ac5 * Math.pow(T, 5)+ac6 * Math.pow(T, 6)+ac7 * Math.pow(T, 7));
double CpVoz = MCpVoz/M;
double MCvVoz = MCpVoz-R;
double CvVoz = MCvVoz/M;
double kVoz = CpVoz/CvVoz;

double HVoz = ((ah0 * Math.pow(T, 0)+ah1 * Math.pow(T, 1)+ah2 * Math.pow(T, 2)+ah3 * Math.pow(T, 3)+ah4 * Math.pow(T, 4)
+ah5 * Math.pow(T, 5)+ah6 * Math.pow(T, 6)+ah7 * Math.pow(T, 7)+ah8 * Math.pow(T, 8)+bh*Math.log(T))+487.755);
double hVoz = HVoz/M;
double UVoz = HVoz - R*T*1000;
double uVoz = UVoz/M;
double SVoz = (as * Math.pow(T, -1))+(as0 * Math.pow(T, 0))+(as1 * Math.pow(T, 1))+(as2 * Math.pow(T, 2))+
(as3 * Math.pow(T, 3))+(as4 * Math.pow(T, 4))+(as5 * Math.pow(T, 5))+(as6 * Math.pow(T, 6))+
(as7 * Math.pow(T, 7))+bs*Math.log(T);
double sVoz = SVoz/M;   
double PiVoz = Math.pow(e,(M*sVoz-M*s0)/R);
double OVoz = T/(T0*PiVoz);
double TVoz = T; //эти все значения надо вывести на экран

}

Источник: https://ru.stackoverflow.com/questions/688731/%D0%B2%D1%8B%D0%B2%D0%BE%D0%B4-%D0%B7%D0%BD%D0%B0%D1%87%D0%B5%D0%BD%D0%B8%D0%B9-%D0%BD%D0%B0-%D1%8D%D0%BA%D1%80%D0%B0%D0%BD-%D1%87%D0%B5%D1%80%D0%B5%D0%B7-gui-java

Share

Тебе может это понравится...