Advertisement
Guest User

Simulator.java

a guest
Jul 6th, 2012
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import javax.swing.JPanel;
  4.  
  5.  
  6. public class Simulator extends JFrame {
  7.  
  8. private final static int dimH = 1000;
  9. private final static int dimV = 500;
  10. private final static int startx = 10;
  11. private final static int starty = 10;
  12. private final static String title = "Test";
  13. public javax.swing.JPanel jpanel1;
  14. public JFrame frame = new JFrame();
  15.  
  16. public Simulator() {
  17. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  18. initcomponents();
  19. }
  20.  
  21. public static void main (String[] args) {
  22. java.awt.EventQueue.invokeLater(new Runnable() {
  23. @Override
  24. public void run() {
  25. new Simulator();
  26. }
  27. });
  28. }
  29.  
  30. // <editor-fold defaultstate="collapsed" desc="COMPONENTS INIT">
  31. public void initcomponents() {
  32. //JFrame frame = new JFrame();
  33. frame.setSize(dimH, dimV);
  34. frame.setTitle(title);
  35. frame.setResizable(false);
  36. Container pane = frame.getContentPane();
  37. /*frame.add( new JPanel() {
  38. public void paintComponent( Graphics g ) {
  39. super.paintComponent(g);
  40. Graphics2D g2 = (Graphics2D)g;
  41. Line2D line = new Line2D.Double(10, 10, 40, 40);
  42. g2.setColor(Color.blue);
  43. g2.setStroke(new BasicStroke(10));
  44. g2.draw(line);
  45. }
  46. });*/
  47. Dimension appletSize = frame.getSize();
  48. int appletHeight = appletSize.height;
  49. int appletWidth = appletSize.width;
  50. // AVALIAR RESOLUÇÃO DO ECRÃ
  51. Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  52. // System.out.println(screenSize.width);
  53. // System.out.println(screenSize.height);
  54. // AVALIAR TAMANHO DA APPLET
  55. // System.out.println("This applet is " + appletHeight + " pixels high by " +
  56. // appletWidth + " pixels wide.");
  57. // DESENHAR FUNDO
  58. Desenho d = new Desenho(startx,starty,appletWidth - 25,appletHeight - 80,Color.blue);
  59. pane.add(d, "Center");
  60. pane.add(new Botoes(), "East");
  61. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  62. frame.setVisible( true );
  63. frame.setLocationRelativeTo(null);
  64. pack();
  65. }// </editor-fold>
  66.  
  67. // <editor-fold defaultstate="collapsed" desc="CLASS DESENHO">
  68. public class Desenho extends JPanel {
  69. int cx,cy,comp,larg;
  70. Color cor;
  71.  
  72. public Desenho (int cx, int cy, int comp, int larg, Color cor) {
  73. this.cx = cx;
  74. this.cy = cy;
  75. this.comp = comp;
  76. this.larg = larg;
  77. this.cor = cor;
  78. }
  79. // frame.add( new JPanel() {
  80. public void paintComponent( Graphics g ) {
  81. super.paintComponent(g);
  82. /*Graphics2D g2 = (Graphics2D)g;
  83. Line2D line = new Line2D.Double(10, 10, 40, 40);
  84. g2.setColor(Color.blue);
  85. g2.setStroke(new BasicStroke(10));
  86. g2.draw(line);*/
  87. g.setColor(cor);
  88. g.fillRect(cx,cy,comp,larg);
  89. }
  90. //});
  91. }// </editor-fold>
  92.  
  93. public class Botoes extends JPanel {
  94. public Botoes () {
  95. System.out.println("Botoes");
  96. JButton start = new JButton("Start");
  97. this.add(start);
  98. JButton sair = new JButton("Exit");
  99. this.add(sair);
  100. }
  101. }
  102.  
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement