What do you mean by "link classes"? What if one class mentions the other? Would that suffice?
i mean if i had a button in the initial frame class how do i get it to open a new grid frame with a variable size? on the first screen there is three buttons each of which will open a new frame with a grid size depending on which button is pressed.
heres the code for the first window..the A B and C buttons will open new frames.
- import javax.swing.*;
-
import java.awt.*;
-
import java.awt.event.*;
-
import java.net.*;
-
import javax.swing.event.*;
-
-
class myscene extends JFrame implements ActionListener
-
{
-
-
public static void main (String[] args)
-
{
-
myscene frame = new myscene();
-
frame.display();
-
}
-
-
void display()
-
{
-
setTitle("The World's Most Amazing Game of Pairs to Ever Have Existed");
-
setDefaultCloseOperation(EXIT_ON_CLOSE);
-
setVisible(true);
-
setSize(600,250);
-
setMinimumSize(new Dimension (550, 200));
-
JPanel panel1 = new JPanel();
-
JPanel panel2 = new JPanel();
-
add(panel1);
-
add(panel2, BorderLayout.SOUTH);
-
panel1.setBackground(Color.black);
-
panel2.setBackground(Color.black);
-
JButton A = new JButton("New 4x3 Game");
-
JButton B = new JButton("New 4x4 Game");
-
JButton C = new JButton("New 5x4 Game");
-
JButton Exit = new JButton("Exit Game");
-
panel2.add(A);
-
panel2.add(B);
-
panel2.add(C);
-
panel2.add(Exit);
-
Exit.setActionCommand("exit");
-
Exit.addActionListener(this);
-
A.setActionCommand("A");
-
A.addActionListener(this);
-
-
URL address = myscene.class.getResource("pairs.jpg");
-
ImageIcon image = new ImageIcon(address);
-
JLabel icon = new JLabel(image);
-
panel1.add(icon);
-
-
}
-
-
protected void Exit()
-
{
-
System.exit(0);
-
}
-
-
protected void New()
-
{
-
-
}
-
public void actionPerformed(ActionEvent event)
-
{
-
String source = event.getActionCommand();
-
-
if(source.equals("A"))
-
{
-
New()
-
}
-
if(source.equals("exit"))
-
{
-
Exit();
-
}
-
}
-
-
}
-
I've started to write the New() method which should open the new frame but i dont know what to say
I've also started the code for the grid window i intended to make the JPanel array Variable by setting the size as ints x and y dependant on which button is pressed.
this is the loop i used to assign a JPanel to each part of the grid
-
-
getContentPane().setLayout(new GridLayout(5,5));
-
-
JPanel[][] q = new JPanel[5][5];
-
-
for (int i=0; i<5; i++)
-
-
{
-
-
for (int j=0; j<5; j++)
-
-
{
-
-
q[i][j] = new JPanel();
-
-
getContentPane().add(q[i][j]);
-
-
}
-
-
}
-
the loop is in a different class called 'Filenew', how would i go about calling this class from the 'myscene; class?