« first day (1 day earlier)    last day (25 days later) » 

10:46 PM
@MadProgrammer are you coming sir?
 
Yep, meeting, debugging...
 
i thought you guys ae having holdiy like us
today is thanksgiving in usa
anywho
could you help to scale my pic
public class Pictures extends JPanel {

@Override
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
Image img;
try {
img = createImageWithText();
g.drawImage(img, 100, 200, this);
} catch (IOException ex) {
Logger.getLogger(Pictures.class.getName()).log(Level.SEVERE, null, ex);
}

}

private BufferedImage createImageWithText() throws IOException {
// BufferedImage bufferedImage = new BufferedImage(100, 200, BufferedImage.TYPE_INT_RGB);
BufferedImage bufferedImage = ImageIO.read(new File("C:\\Users\\Izak\\Desktop\\pictures\\photo 2.jpg"));
 
does my code look ok to you?
 
You're using paint instead paintComponent, you're not calling super.paint; you're loading the image each time paint is called, which is waste of resources and could actually affect the performance of the program...
 
11:01 PM
@Override
public void paintComponent(Graphics g) {

Graphics2D g2d = (Graphics2D) g;
super.paint(g2d);
Image img;
try {
img = createImageWithText();
// g.drawImage(img, 100, 200, this);
g.drawImage(img.getScaledInstance(100, -1, Image. SCALE_SMOOTH), 0, 0, this);
} catch (IOException ex) {
Logger.getLogger(Pictures.class.getName()).log(Level.SEVERE, null, ex);
}

}
looks better?
gives me Exception in thread "AWT-EventQueue-0" java.lang.StackOverflowError
but when I use paint the error is going away
why?
 
super.paint within paintComponent, use super.paintComponent, always call the super of the method you are overriding (in this context)
And paintComponent doesn't need t be public ;)
 
ya that makes sense
when I get rid of public , complier complain
 
I will apply what you said
Would it be ok if I ask last question plz?
my question is can I add the picture to jpanel
like
JPanel jp = new JPanel();
jp.setSize(100,200);
// BufferedImage myPicture = ImageIO.read(new File("C:\\Users\\Izak\\Desktop\\pictures\\photo 2.jpg"));
//
// JLabel picLabel = new JLabel(new ImageIcon(myPicture));

//jp.add(picLabel, BorderLayout.WEST);
jp.add(new Pictures());
jf.add(jp);
jf.setVisible(true);
but when I do , it just show me the small spot why?
 
11:18 PM
You'd have to supply a means to pass the image to the Pictures panel, either via a constructor or setter method
 
what charcterstic of JPanel has to be changed?
 
The constructor and/or a setter/getter which allows you to supply the image. The paintComponent, obviously and if you want to maintain the size of the image in relationship to the panel, you might need a ComponentListener to monitor for changes to the size of the panel...
 
ya I got it
so for each picture I need to have a class that override paintComponent
and add the class that extends JPanel and override paintCOmponent to the JFrame
Did I get that right?
 
Yes, I guess. You only need a single class with the functionality, of which you create mutliple instances, but that's the general theme..
 
K I got you rpoint
what do you give me for my effort from 0 to 10?
thank you for your help. I apperciate your kindness. Happy thanksgiving to you as well.
I got go to eat Turkey
talk to you to soon :)
 
11:35 PM
I'd give you an 8 ;)
 
thank you such a motivation for me :)
 

« first day (1 day earlier)    last day (25 days later) »