Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JOptionPane;
- public class JFrameFruta extends javax.swing.JFrame {
- /**
- * Creates new form JFrameFruta
- */
- public JFrameFruta() {
- initComponents();
- }
- /**
- * 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() {
- jPanel1 = new javax.swing.JPanel();
- Icon1 = new javax.swing.JLabel();
- Icon2 = new javax.swing.JLabel();
- Icon3 = new javax.swing.JLabel();
- btnSortear = new javax.swing.JButton();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- Icon1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
- Icon1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/1.jpg"))); // NOI18N
- Icon2.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
- Icon2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/2.jpg"))); // NOI18N
- Icon3.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
- Icon3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/3.jpg"))); // NOI18N
- btnSortear.setText("Sortear");
- btnSortear.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- btnSortearActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
- jPanel1.setLayout(jPanel1Layout);
- jPanel1Layout.setHorizontalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
- .addGap(42, 42, 42)
- .addComponent(Icon1)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 75, Short.MAX_VALUE)
- .addComponent(Icon2)
- .addGap(62, 62, 62)
- .addComponent(Icon3)
- .addGap(42, 42, 42))
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(btnSortear, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(151, 151, 151))
- );
- jPanel1Layout.setVerticalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGap(86, 86, 86)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(Icon1)
- .addComponent(Icon2)
- .addComponent(Icon3))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 82, Short.MAX_VALUE)
- .addComponent(btnSortear, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(33, 33, 33))
- );
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- );
- pack();
- }// </editor-fold>
- private void btnSortearActionPerformed(java.awt.event.ActionEvent evt) {
- int R1 = (int)(Math.round(Math.random()*2)+1);
- int R2 = (int)(Math.round(Math.random()*2)+1);
- int R3 = (int)(Math.round(Math.random()*2)+1);
- Icon1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/"+R1+".jpg")));
- Icon2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/"+R2+".jpg")));
- Icon3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/"+R3+".jpg")));
- if(R1 == R2 && R2 == R3){
- JOptionPane.showMessageDialog(null, "Parabéns, você ganhou");
- }
- else{
- JOptionPane.showMessageDialog(null, "Você perdeu, trouxa.");
- }
- // 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(JFrameFruta.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(JFrameFruta.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(JFrameFruta.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(JFrameFruta.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 JFrameFruta().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JLabel Icon1;
- private javax.swing.JLabel Icon2;
- private javax.swing.JLabel Icon3;
- private javax.swing.JButton btnSortear;
- private javax.swing.JPanel jPanel1;
- // End of variables declaration
- }
Add Comment
Please, Sign In to add comment