Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.*;
- import javax.swing.JPanel;
- public class Simulator extends JFrame {
- private final static int dimH = 1000;
- private final static int dimV = 500;
- private final static int startx = 10;
- private final static int starty = 10;
- private final static String title = "Test";
- public javax.swing.JPanel jpanel1;
- public JFrame frame = new JFrame();
- public Simulator() {
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- initcomponents();
- }
- public static void main (String[] args) {
- java.awt.EventQueue.invokeLater(new Runnable() {
- @Override
- public void run() {
- new Simulator();
- }
- });
- }
- // <editor-fold defaultstate="collapsed" desc="COMPONENTS INIT">
- public void initcomponents() {
- //JFrame frame = new JFrame();
- frame.setSize(dimH, dimV);
- frame.setTitle(title);
- frame.setResizable(false);
- Container pane = frame.getContentPane();
- /*frame.add( new JPanel() {
- public void paintComponent( Graphics g ) {
- super.paintComponent(g);
- Graphics2D g2 = (Graphics2D)g;
- Line2D line = new Line2D.Double(10, 10, 40, 40);
- g2.setColor(Color.blue);
- g2.setStroke(new BasicStroke(10));
- g2.draw(line);
- }
- });*/
- Dimension appletSize = frame.getSize();
- int appletHeight = appletSize.height;
- int appletWidth = appletSize.width;
- // AVALIAR RESOLUÇÃO DO ECRÃ
- Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
- // System.out.println(screenSize.width);
- // System.out.println(screenSize.height);
- // AVALIAR TAMANHO DA APPLET
- // System.out.println("This applet is " + appletHeight + " pixels high by " +
- // appletWidth + " pixels wide.");
- // DESENHAR FUNDO
- Desenho d = new Desenho(startx,starty,appletWidth - 25,appletHeight - 80,Color.blue);
- pane.add(d, "Center");
- pane.add(new Botoes(), "East");
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- frame.setVisible( true );
- frame.setLocationRelativeTo(null);
- pack();
- }// </editor-fold>
- // <editor-fold defaultstate="collapsed" desc="CLASS DESENHO">
- public class Desenho extends JPanel {
- int cx,cy,comp,larg;
- Color cor;
- public Desenho (int cx, int cy, int comp, int larg, Color cor) {
- this.cx = cx;
- this.cy = cy;
- this.comp = comp;
- this.larg = larg;
- this.cor = cor;
- }
- // frame.add( new JPanel() {
- public void paintComponent( Graphics g ) {
- super.paintComponent(g);
- /*Graphics2D g2 = (Graphics2D)g;
- Line2D line = new Line2D.Double(10, 10, 40, 40);
- g2.setColor(Color.blue);
- g2.setStroke(new BasicStroke(10));
- g2.draw(line);*/
- g.setColor(cor);
- g.fillRect(cx,cy,comp,larg);
- }
- //});
- }// </editor-fold>
- public class Botoes extends JPanel {
- public Botoes () {
- System.out.println("Botoes");
- JButton start = new JButton("Start");
- this.add(start);
- JButton sair = new JButton("Exit");
- this.add(sair);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement