Web Analytics Made Easy -
StatCounter JApplet Problem - CodingForum

Announcement

Collapse
No announcement yet.

JApplet Problem

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • JApplet Problem

    Hello, I have a dice rolling app that I am trying to make into an applet
    I built the Applet but when I go to run it, it appears blank. can anyone help me?
    I have the code here

    Code:
    package dieapplet;
    
    
    
    
    import java.awt.*
    
    import java.awt.event.*;
    import javax.swing.*;
    
    
    public class DieApplet extends JApplet {
        JTextArea text;
        JButton clear;
        JButton roll;
        public void g(){
            JFrame frame = new JFrame();
            JPanel panel = new JPanel();
            clear = new JButton("Clear");
            text = new JTextArea(10,20);
            text.setLineWrap(true);
            JScrollPane scroller = new JScrollPane(text);
            scroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
            scroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
            panel.add(scroller);
            frame.getContentPane().add(BorderLayout.CENTER, panel);
            frame.getContentPane().add(BorderLayout.SOUTH, clear);
            clear.addActionListener(new Myinner());
            roll = new JButton("click to roll");
            roll.addActionListener(new Mi1());
            frame.getContentPane().add (BorderLayout.NORTH, button);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(300,300);
            frame.setVisible(true);
        }
            
            
        public class Myinner implements ActionListener{
    
            public void actionPerformed (ActionEvent event) {
           text.setText("");
            }
        }
            public class Mi1 implements ActionListener{
                public void actionPerformed(ActionEvent event) {
            int number = (int)(Math.random() * 7);
            text.append("your roll is " + number + "\n");
            }
            }  
    }
Working...
X