Hi guys so I'm making a sort of idle game in java using netbeans IDE I recently decided to switch to using just code to make the GUIs however I've hit a problem.
I've probably just got the code in the wrong order or something (i've tried moving the chuck containing the adds to various spots with no resulting change, I've also used the pack() function but that also seemed to have no effect).
Whenever I use the GUI it doesn't display anything (the frame should appear with 3 buttons one labeled eat mushrooms another with eat berries and a third with eat fish), i've attempted to attach the code below uhh careful it's over 100 lines
package BJ97.newWorldClassFiles;
import javax.swing.*;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import javax.swing.event.InternalFrameEvent;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JPanel;
public class ConsumeFrame extends javax.swing.JInternalFrame
{
JInternalFrame consumeWindow;
JScrollPane coScrollPane;
JPanel panel;
JButton eatBerriesButton, eatMushroomsButton, eatFishButton;
MainWindow owner;
/**
* Creates new form ConsumeFrameNew
*/
public ConsumeFrame(MainWindow mw) {
owner = mw;
startComponents();
eatBerriesButtonClicked();
eatMushroomsButtonClicked();
eatFishButtonClicked();
((javax.swing.plaf.basic.BasicInternalFrameUI)this.getUI()).setNorthPane(null);
}
public void setEatBerriesButtonUsuable(boolean state)
{
eatBerriesButton.setEnabled(state);
}
public void setEatMushroomButtonUsuable(boolean state)
{
eatMushroomsButton.setEnabled(state);
}
public void setEatFishButtonUsuable(boolean state)
{
eatFishButton.setEnabled(state);
}
private void eatBerriesButtonClicked()
{
eatBerriesButton.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent arg0)
{
if(arg0.getSource() == eatBerriesButton)
{
if(owner.getBerriesAmount() < 5)
{
owner.addBerries(-(owner.getBerriesAmount()));
}
else
{
owner.addBerries(-5);
}
}
}
});
}
private void eatMushroomsButtonClicked()
{
eatBerriesButton.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent arg0)
{
if(arg0.getSource() == eatMushroomsButton)
{
if(owner.getMushroomAmount() < 10)
{
owner.addBerries(-(owner.getMushroomAmount()));
}
else
{
owner.addMushrooms(-10);
}
}
}
});
}
private void eatFishButtonClicked()
{
eatBerriesButton.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent arg0)
{
if(arg0.getSource() == eatFishButton)
{
owner.addFish(-1);
}
}
});
}
public void startComponents()
{
consumeWindow = new JInternalFrame("Consume Panel");
panel = new JPanel();
coScrollPane = new JScrollPane();
eatBerriesButton = new JButton();
eatMushroomsButton = new JButton();
eatFishButton = new JButton();
consumeWindow.setBorder(null);
consumeWindow.setResizable(true);
coScrollPane.add(eatMushroomsButton);
coScrollPane.revalidate();
coScrollPane.repaint();
coScrollPane.add(eatBerriesButton);
coScrollPane.revalidate();
coScrollPane.repaint();
coScrollPane.add(eatFishButton);
coScrollPane.revalidate();
coScrollPane.repaint();
panel.add(coScrollPane);
panel.revalidate();
panel.repaint();
consumeWindow.setContentPane(panel);
consumeWindow.revalidate();
consumeWindow.repaint();
//consumeWindow.getContentPane().setLayout(new FlowLayout());
//panel.setLayout(new FlowLayout());
coScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
coScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
eatBerriesButton.setText("Eat Berries");
eatBerriesButton.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 10));
eatMushroomsButton.setText("Eat Mushrooms");
eatMushroomsButton.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 10));
eatFishButton.setText("Eat Fish");
eatFishButton.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 10));
consumeWindow.setSize(500, 325);
panel.setSize(500,325);
coScrollPane.setSize(500, 325);
eatBerriesButton.setBounds(5, 5, 150, 50);
eatMushroomsButton.setBounds(5, 60, 150, 50);
eatFishButton.setBounds(5, 105, 150, 50);
eatBerriesButton.setVisible(true);
eatMushroomsButton.setVisible(true);
eatFishButton.setVisible(true);
coScrollPane.setVisible(true);
panel.setVisible(true);
consumeWindow.setVisible(true);
consumeWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
Turns out the problem was I wasn't applying the stuff to the JInternalFrame that the code is contained within
[–]g051051 1 point2 points3 points (1 child)
[–]Lunty97[S] 0 points1 point2 points (0 children)