Guest User

DemoGuiComsol

a guest
Dec 13th, 2012
561
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.99 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package demoguicomsol;
  6.  
  7. import com.comsol.model.Model;
  8. import com.comsol.model.util.*;
  9. import com.comsol.modelguiswing.SwingGraphicsPanel;
  10. import java.awt.*;
  11. import javax.swing.*;
  12. import java.lang.*;
  13.  
  14. /**
  15.  *
  16.  * @author andres
  17.  */
  18. public class DemoGuiComsol {
  19.  
  20.     /**
  21.      * @param args the command line arguments
  22.      */
  23.     public static void main(String[] args) {
  24.         // TODO code application logic here
  25.         DemoGuiComsol demo = new DemoGuiComsol();
  26.         demo.init();
  27.         demo.start();
  28.  
  29.     }
  30.     private Model model;
  31.     private JFrame frame;
  32.  
  33.     public void init() {
  34.         try{
  35.         ModelUtil.connect("localhost", 2036);
  36.         }
  37.        
  38.         catch(java.lang.Throwable t) {
  39.         System.out.println( t.getClass().getName() ); //this'll tell you what class has been thrown
  40.         t.printStackTrace(); //get a stack trace
  41.         }
  42.         //ModelUtil.initStandalone(true);
  43.     }
  44.  
  45.     public void start() {
  46.         frame = new JFrame("Beam GUI - based on COMSOL Multiphysics");
  47.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  48.         frame.setSize(1000, 730);
  49.         JPanel mainPanel = new JPanel();
  50.         frame.getContentPane().add(mainPanel);
  51.         mainPanel.setLayout(new BorderLayout());
  52.         model = BeamModel.run();
  53.         model.sol("sol1").runAll();
  54.         model.result("pg1").set("window", "window1");
  55.         model.result("pg1").run();
  56.        
  57.         try{
  58.         SwingGraphicsPanel graphicsPanel =
  59.         new SwingGraphicsPanel("window1", "Window1");
  60.         mainPanel.add(graphicsPanel, BorderLayout.CENTER);
  61.         }
  62.         catch(java.lang.Throwable t) {
  63.         System.out.println( t.getClass().getName() ); //this'll tell you what class has been thrown
  64.         t.printStackTrace();
  65.         }
  66.         frame.setVisible(true);
  67.        
  68.         ModelUtil.disconnect();
  69.  
  70.  
  71.     }
  72.    
  73.    
  74.    
  75. }
Advertisement
Add Comment
Please, Sign In to add comment