I have these code below for the button :
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class Coba extends Applet
{
Button button1;
public void init()
{
Font font = new Font("TimesRoman",Font.BOLD,16);
setFont(font);
button1 = new Button("Level Easy");
resize(250,250);
LevelEasy lvleasy = new LevelEasy();
button1.addActionListener(lvleasy);
//button1.addActionListener(this);
add("Left",button1);
}
private class LevelEasy implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
Cross4 cross = new Cross4();
}
}
//----------------------------------------------
}
And one file named Cross4.class that i want to call with a button..
Here is the code for Cross4 :
import java.applet.*;
import java.awt.*;
public class Cross4 extends Applet {
final static int LebarKotakTTS = 40;
final static int TinggiKotakTTS = 40;
final static int JmlhKotakLebar = 12;
final static int JmlhKotakTinggi = 12;
final static int QuestAreaHeight = 100;
/*---------------------------------------------------------------*/
final static int layout[][] = {
{-1, 1, 0, 2, 0, 0, 3, -1, 4, 0, 5, 0},
{6, 0, 0, 0, -1, -1, 0, -1, -1, -1, 0, -1},
{-1, 0, -1, 0, -1, 7, 0, 0, 8, -1, 0, -1},
{9, 0, 0, 0, 10, -1, -1, -1, 11, 0, 0, -1},
{0, -1, -1, 12, 0, 0, 13, -1, 0, -1, -1, -1},
{0, -1, 14, -1, 0, -1, 0, -1, 15, 0, 0, 16},
{17, 0, 0, 18, 0, -1, 19, 20, 0, -1, -1, 0},
{0, -1, 0, 0, -1, 21, 0, 0, 0, -1, -1, 0},
{22, 23, 0, 0, -1, 0, -1, 0, -1,24, 0, 0},
{-1, 0, -1, 25, 0, 0, -1, 0, -1, 0, -1, -1},
{26, 0, 0, -1, -1, 0, -1, 27, 0, 0, 0, -1},
{-1, -1, -1, -1, -1, 0, -1, 0, -1, 0, -1, -1}
};
/*---------------------------------------------------------------*/
public void init() {
int viewWidth;
int left, top;
//resize(200,200);
NewGame();
}
/*---------------------------------------------------------------*/
public void NewGame() {
for (int j = 0 ; j < JmlhKotakTinggi ; j++) {
for (int i = 0 ; i < JmlhKotakLebar ; i++) {
gGuesses[i][j] = "";
}
}
}
/*----------------------------------------------*/
public void paint(Graphics g) {
int left = 0;
int right = 0;
int top = 0;
int bottom = 0;
int tempLeft = 0;
int tempRight = 0;
int tempTop = 0;
int viewWidth;
int viewHeight;
Font f = new java.awt.Font("Helvetica", Font.BOLD, 12);
g.setFont(f);
Font numFont = new java.awt.Font("Helvetica", Font.BOLD, 10);
Font answerFont = new java.awt.Font("Helvetica", 0, 18);
Font questionFont = new java.awt.Font("Courier", Font.BOLD, 12);
FontMetrics answerFontMetrics = g.getFontMetrics(answerFont);
FontMetrics questionFontMetrics = g.getFontMetrics(questionFont);
viewWidth = JmlhKotakLebar * LebarKotakTTS;
viewHeight = JmlhKotakTinggi * TinggiKotakTTS;
top = viewHeight + ((size().height / 2) - (viewHeight / 2));
left = (size().width / 2) - (viewWidth / 2);
g.setColor(Color.black);
g.draw3DRect(left, top, viewWidth, QuestAreaHeight, true);
top = (size().height / 2) - (viewHeight / 2);
left = (size().width / 2) - (viewWidth / 2);
for (int j = 0 ; j < JmlhKotakTinggi ; j++)
{
for (int i = 0 ; i < JmlhKotakLebar ; i++)
{
tempLeft = left + (i * LebarKotakTTS);
tempTop = top + (j * TinggiKotakTTS);
g.setColor(Color.black);
g.drawRect(tempLeft, tempTop, LebarKotakTTS , TinggiKotakTTS );
if (layout[j][i] == -1){
g.setColor(Color.black);
g.fillRect(tempLeft, tempTop, LebarKotakTTS, TinggiKotakTTS);
}
else if (layout[j][i] != 0)
{
String numStr = String.valueOf(layout[j][i]);
g.setFont(numFont);
g.drawString(numStr, tempLeft + 4 , tempTop + 10);
}
}
}
}
/*------------------------------------------------------------*/
}
The problem is why when i clicked on the button, it doesn't do anything.. Is there something wrong in my code??
Can anyone please help me or? :'(