Ir para conteúdo
Fórum CódigoFonte.net
halisonvitorino

Rodar programa java na pagina web

Recommended Posts

Caros,

tem como eu fazer um programa java rodar em uma pagina web?

Segue o codigo:


package view;
import view.Janela;

public class Programa {
public static void main( String[ ] args) {    
    new Janela();
}
}

 

package view;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import control.CarroThread;
import java.applet.*;
public class Janela extends Applet implements ActionListener {
    private JFrame jfJanela;
    private JPanel jpPrincipal;
    private JButton btnCorrida, btnCancel;
    private ImageIcon imgCarro1, imgCarro2, imgCarro3, pista;

public Janela() {
    jfJanela = new JFrame("Nasa Ralli Sport");
    jfJanela.setSize(950,700);
    jfJanela.setLocationRelativeTo(null);
    jfJanela.setBackground(Color.black);
    jfJanela.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10)); 
    jfJanela.setResizable(false);
    jfJanela.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

    jpPrincipal = new JPanel();
    jpPrincipal.setPreferredSize(new Dimension(895, 540)); 
    jpPrincipal.setLayout(null); 
    jpPrincipal.setBackground(Color.white);
    
    ImageIcon img = new ImageIcon("./src/imagens/pista3.png");
    JLabel label  = new JLabel(img);
    label.setBounds(0, 0, 900, 550);
        
    imgCarro1   = new ImageIcon("./src/imagens/carro1.png");
    imgCarro2   = new ImageIcon("./src/imagens/carro2.png");
    imgCarro3   = new ImageIcon("./src/imagens/carro3.png");
        
    btnCorrida = new JButton("Iniciar");
    btnCancel  = new JButton("Parar");
    btnCorrida.setBounds(300, 450, 100, 50);
    btnCancel .setBounds(500, 450, 100, 50);
    btnCorrida.addActionListener(this);
    btnCancel .addActionListener(this);
    
    jfJanela   .add(jpPrincipal);
    jpPrincipal.add(label);
    jfJanela   .add(btnCancel);
    jfJanela   .add(btnCorrida);
        
    jfJanela   .setVisible(true);
    jpPrincipal.setVisible(true);
        
    this.repaint();
}
public JLabel JLabelCarros(String nome, ImageIcon img, int posX, int posY) {
CarroThread carro = new CarroThread(nome, img, posX, posY);
carro.setSize(10, 500);
carro.setVisible(true);
jpPrincipal.add(carro);
return carro;
}

@Override
public void actionPerformed(ActionEvent dispara) {if (dispara.getSource() == this.btnCorrida) {
    this.jpPrincipal.add(JLabelCarros("Carro1", imgCarro1, 0, 30));
    this.jpPrincipal.add(JLabelCarros("Carro2", imgCarro2, 0, 30));
    this.jpPrincipal.add(JLabelCarros("Carro3", imgCarro3, 0, 30));}
if (dispara.getSource() == this.btnCancel) {System.exit(0);}
}}
 

package control;
import java.util.Random;

import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
public class CarroThread extends JLabel implements Runnable {
private Thread carroThread = null;
private int posX;
private int posY;
private ImageIcon imagem;

public CarroThread() {
}

public CarroThread(String nome, ImageIcon img, int posX, int posY){
    super(img);
    this.imagem = img;
    this.posX   = posX;
    this.posY   = posY;
    carroThread = new Thread(this, nome);
    carroThread.start();
}
@Override
public void run() {
    posX += new Random().nextInt(2)*10;
    this.setLocation( posX, posY);
    
    for (int i = posX ; i<800; i++){
        JOptionPane pane = new JOptionPane(this.posX);}
        
    if (posX >=  800)    return;
        try {Thread.sleep( new Random().nextInt(10) * 10); run();} 
        catch ( Exception e) {e.printStackTrace();}
    
    }

}
 

 

 

Compartilhar este post


Link para o post
Compartilhar em outros sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Visitante
Responder

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Processando...

×
×
  • Criar Novo...