/ जावा में एक छवि बनाने में मदद की ज़रूरत है - जावा, छवि, स्विंग, टाइमर, पेंटकंपोनेंट

जावा में एक छवि ड्राइंग में मदद की ज़रूरत है - जावा, छवि, स्विंग, टाइमर, पेंटकंपोनेंट

मैं जो करने की कोशिश कर रहा हूं वह एक छवि प्रदर्शन हैस्क्रीन पर सेकंड की मात्रा के लिए और फिर गायब हो जाते हैं और फिर उसकी जगह एक और खींचा जाता है, मुझे पहली छवि प्रदर्शित करने के लिए मिली है लेकिन दूसरा एक काम नहीं करता है। नोट: मैं आकृतियों को आकर्षित कर सकता हूं लेकिन छवि को नहीं

package com.mainwindow.draw;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Timer;
import javax.swing.ImageIcon;
import javax.swing.JPanel;

@SuppressWarnings("serial")
public class MainWindow extends JPanel {

Image Logo;
Image Menu;
String LogoSource = "Gimijes.png";
String menuEntity = "Menu.png";
Boolean draw = true;

static Boolean timeout = false;

public MainWindow() {
ImageIcon ii = new ImageIcon(this.getClass().getResource(LogoSource));
Logo = ii.getImage();
ImageIcon mii = new ImageIcon(this.getClass().getResource(menuEntity));
Menu = mii.getImage();
Timer timer = new Timer(1000, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
draw = false;
timeout = true;
repaint();

}
});

timer.start();
};

@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
if (draw == true) {
//draw Gimijes.png (on screen for 5 seconds)
g2.drawImage(Logo, 0, 0, null);
}
if (timeout  == true) {
g2.drawImage(Menu, getWidth(), getHeight(), null);

}
}
}

अगर किसी को पता है कि यह काम करने के लिए मुझे वास्तव में आभारी होंगे।

उत्तर:

उत्तर № 1 के लिए 1

समस्या नई छवि की स्थिति के साथ थी। यदि आप मौजूदा छवि को ओवरराइड करना चाहते हैं तो समान समन्वय (स्थिति [0,0]) का उपयोग करें

@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
if (draw == true) {
// draw Gimijes.png (on screen for 5 seconds)
g2.drawImage(Logo, 0, 0, null);
}
if (timeout == true) {
g2.drawImage(Menu, 0, 0, null);
}
}