Я пытаюсь получить изображение для отображения в кадре для игры, которую я создаю.Вместо того, чтобы расширять JPanels или JFrame, я просто создаю несколько классов фреймов и один класс действий. В настоящее время у меня возникают проблемы с отображением изображения на тестовом фрейме, который я создал.Мой код компилируется, но когда я нажимаю на фрейм, он выключается.Спасибо!
PS это только часть моего кода.Я слышал, что не стоит публиковать общий код онлайн.
Код:
public void testframe(){
testframe = new Frame("Main Menu");
testframe.setSize(1600,1600);
try{
myPicture = ImageIO.read(new File("basic.png"));
}
catch(IOException e){
e.printStackTrace();
//FirstFrame.setVisible(true);
//testframe.setVisible(false);
}
JLabel picLabel = new JLabel(new ImageIcon(myPicture));
testframe.add(picLabel);
//testframe.drawImage(myPicture,"png", );
testframe.setVisible(true);
}
private void showButtonDemo(){
Font myFont = new Font("Serif", Font.ITALIC | Font.BOLD, 12);
Font newFont = myFont.deriveFont(50F);
headerLabel.setText("SNAKE GAME");
headerLabel.setFont(newFont);
statusLabel.setText("By Tejas and Ashwin");
statusLabel.setFont(newFont);
Button startButton = new Button("Start Game");//begins game
Button snakecolorButton = new Button("Choose Snake Color");//selects snake color
Button themeColorButton = new Button("Choose Theme");//selects two colors(1 primary and 1 secondary)
Button InstructionsButton = new Button("Instructions");
Button testbutton = new Button("test");
testbutton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
//testframe();
//testframe.setVisible(true);
FirstFrame.setVisible(false);
}
});