- Is there a way that I can set the
JFrame
to be transparent while still leaving the Buttons / text unaffected?
- If not, how can I make the
JFrame
transparent without using .setUndecorated(true)
?
- This is a totally different question, but how would I go about adding a gradient as the background color instead of having it be set to one solid color?
- Click here to see what the JFrame looks like when the program runs!
class PlayAgain extends JPanel
{
private JFrame nextFrame;
public PlayAgain()
{
nextFrame = new JFrame("Tic-Tac-Toe");
nextFrame.setSize(250,125);
nextFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel(new GridBagLayout());
nextFrame.add(panel);
GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets(10,10,10,10);
class ButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
nextFrame.dispose();
frame.dispose();
XorOFrameGRID obj = new XorOFrameGRID();
}
}
class ClickNo implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
frame.dispose();
nextFrame.dispose();
}
}
//CREATING BUTTONS & LABELS
JLabel WLT;
c.gridx = 0;
c.gridy = 0;
c.gridwidth = 3;
JLabel title = new JLabel("Would you like to play again?");
if (isWin() == 1)
{
WLT = new JLabel("YOU WON!");
panel.add(WLT,c);
}
else if (isWin() == 2)
{
WLT = new JLabel("YOU LOST!");
panel.add(WLT,c);
}
else if (isWin() == 3)
{
WLT = new JLabel("YOU TIED!");
panel.add(WLT,c);
}
JLabel or = new JLabel("or");
JButton yes = new JButton("Yes");
ActionListener listener1 = new ButtonListener();
yes.addActionListener(listener1);
JButton no = new JButton("No");
ActionListener listener2 = new ClickNo();
no.addActionListener(listener2);
c.gridwidth = 0;
//1ST COLUMN
c.anchor = GridBagConstraints.LINE_END;
c.weighty = 10;
c.gridx = 0;
c.gridy = 2;
panel.add(no,c);
//2ND COLUMN
//adds "or"
c.anchor = GridBagConstraints.CENTER;
c.gridx = 1;
c.gridy = 2;
panel.add(or,c);
//adds title
c.weighty = 0;
c.gridwidth = 3;
c.gridx = 0;
c.gridy = 1;
panel.add(title,c);
//3RD COLUMN
c.gridwidth = 0;
c.weighty = 3; // changes weight
c.anchor = GridBagConstraints.LINE_START;
c.gridx = 2;
c.gridy = 2;
panel.add(yes,c);
nextFrame.pack();
nextFrame.setLocationRelativeTo(null);
nextFrame.setResizable(false);
nextFrame.setVisible(true);
nextFrame.toFront();
}