public class MinesweeperMenu extends MinesweeperPanel{
private JPanel picture = new JPanel();
private JButton play = new JButton("Play");
private JButton highScores = new JButton("High Score and \nStatistics");
private JButton changeMap = new JButton("Create Custom \nor Change Map");
private JButton difficulty = new JButton("Custom or\nChange Difficulty");
private JButton user = new JButton("Change User");
Image img;
public MinesweeperMenu()
{
// Set Layout for the menu
LayoutManager menuLayout = new BoxLayout(menu, BoxLayout.Y_AXIS);
menu.setLayout(menuLayout);
// Set Layout for the window
LayoutManager windowLayout = new BorderLayout();
window.setLayout(windowLayout);
// Add buttons to the panels
menu.add(play);
menu.add(highScores);
menu.add(changeMap);
menu.add(difficulty);
menu.add(user);
// Add picture to the frame
try{
File input = new File("./setup/images/MineMenuPicture.jpg");
img = ImageIO.read(input);
}
catch(IOException ie)
{
System.out.println(ie.getMessage());
}
// Add action listeners
changeMap.addActionListener(new ChangeMapListener());
}
public void paintComponent(Graphics g)
{
// POSITION OF THE PICTURE
int x = 650;
int y = 585;
g.drawImage(img, x, y, null);
}
public void displayFrame()
{
// Display Frame
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setVisible(true);
}
public static void main(String[] args)
{
MinesweeperMenu menu = new MinesweeperMenu();
window.pack();
menu.displayFrame();
window.repaint();
}
}
public class MinesweeperPanel extends JFrame{
public static final Color COLOR_KEY = new Color(220, 110, 0);
// Initialize all the objects
public static JFrame window = new JFrame("Minesweeper++");
public static JPanel menu = new JPanel();
// Close the current window
public static void close()
{
window.setVisible(false);
window.dispose();
}
}
मुझे फ्रेम में प्रदर्शित करने के लिए मेरी छवि नहीं मिल सकती है। मैंने सब कुछ करने की कोशिश की है, लेकिन मुझे लगता है कि यह एक गलती है कि मैं महसूस नहीं कर रहा हूं क्योंकि मैं जावा स्विंग में नया हूं। किसी भी तरह की सहायता का स्वागत किया जाएगा।जावा स्विंग में एक छवि प्रदर्शित करना
क्या आपने यह सुनिश्चित करने के लिए जांच की है कि img! = Null? मैं यह सुनिश्चित करने के लिए कि छवि को सही तरीके से सेटअप किया जा रहा है, मैं इसे खींचने से पहले या तो एक प्रिंट स्टेटमेंट के साथ एक चेक डिबग या डाल दूंगा। –
'नया जेबटन ("उच्च स्कोर और \ n सांख्यिकी"); 'जेबटन' लाइन ब्रेक का समर्थन नहीं करता है। लाइन ब्रेक पाने के लिए एचटीएमएल का उपयोग करना संभव है, लेकिन अक्षम होने पर बटन गलत दिखाई देगा। –