例如
class a{ public void excute() {
new b();
}
private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {}
private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {}
public String test1()
{
String velocity = jTextField1.getText();
return velocity;
}
public String test2()
{
String pressure = jTextField2.getText();
return pressure;
}}
------------------------------------------------------------------------------------------
class b{
String v_set=new a().test1();
String p_set=new a().test2();
public void main ()
{
System.out.println(v_set+p_set);
}
}
----------------------------------------------------------------------------------------------
请问为什么b类中的v_set和p_set取不到jtextfield中输入的值?
class a{ public void excute() {
new b();
}
private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {}
private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {}
public String test1()
{
String velocity = jTextField1.getText();
return velocity;
}
public String test2()
{
String pressure = jTextField2.getText();
return pressure;
}}
------------------------------------------------------------------------------------------
class b{
String v_set=new a().test1();
String p_set=new a().test2();
public void main ()
{
System.out.println(v_set+p_set);
}
}
----------------------------------------------------------------------------------------------
请问为什么b类中的v_set和p_set取不到jtextfield中输入的值?
* Creates new form mypanel
*/
public mypanel() {
initComponents();
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.setVisible(true);
} /**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() { jTextField1 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jTextField2 = new javax.swing.JTextField();
jTextField3 = new javax.swing.JTextField(); jTextField1.setText("jTextField1"); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jButton1.setText("bc setting");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
}); jButton2.setText("physical_setting");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jButton3.setText("set_velocity&pressure");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
}); jTextField2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField2ActionPerformed(evt);
}
}); jTextField3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField3ActionPerformed(evt);
}
}); .....
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
final MacroExecuteAction mea = SystemAction.get(MacroExecuteAction.class);
mea.setMacro(new boundary_setting());
mea.performAction();
} private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
final MacroExecuteAction mea = SystemAction.get(MacroExecuteAction.class);
mea.setMacro(new physical_setting());
mea.performAction();
} private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
final MacroExecuteAction mea = SystemAction.get(MacroExecuteAction.class);
mea.setMacro(new set_velocity_pressure());
mea.performAction();
}
private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
} private void jTextField3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
} /**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(mypanel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(mypanel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(mypanel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(mypanel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold> /* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new mypanel().setVisible(true);
}
});
}
public String test1()
{
String velocity = jTextField2.getText();
return velocity;
}
public String test2()
{
String pressure = jTextField3.getText();
return pressure;
}
}
------------------------------------------------
这个是jframe的UI,我所有的输入和执行都在这个上面,输入使用了jtextfield,执行是jbutton.
------------------------------------------------public class set_velocity_pressure extends StarMacro {
String velocity=new mypanel().test1();
double v=Double.valueOf(velocity).doubleValue();
String pressure=new mypanel().test2();
double p=Double.valueOf(pressure).doubleValue();
public void execute() {
Simulation sim = this.getActiveSimulation();
sim.println("settings are completed.");
execute0();
}
private void execute0() { Simulation simulation_0 =
getActiveSimulation(); Region region_0 =
simulation_0.getRegionManager().getRegion("fill pipe"); Boundary boundary_0 =
region_0.getBoundaryManager().getBoundary("inlet"); MassFlowRateProfile massFlowRateProfile_0 =
boundary_0.getValues().get(MassFlowRateProfile.class); massFlowRateProfile_0.getMethod(ConstantScalarProfileMethod.class).getQuantity().setValue(v); Boundary boundary_1 =
region_0.getBoundaryManager().getBoundary("outlet"); StaticPressureProfile staticPressureProfile_0 =
boundary_1.getValues().get(StaticPressureProfile.class); staticPressureProfile_0.getMethod(ConstantScalarProfileMethod.class).getQuantity().setValue(p);
}
}
---------------------------------------------------------------
这个类是jbutton3所执行的内容,完成设定速度和压力。
问题出在标红的这一行 ,无法获取jtext的输入值。
你的main方法为毛是 public void main ()额,对JAVA不熟,不是学这个的。我是想搞机械设计的,想做个二次开发,但是对编程懂的不多。