On Aug 8, 2:44 pm, "John B. Matthews" <nos...@nospam.invalid> wrote:
cause you to lose some of your GUI but the GUI will not be able to
respond until the image gathering code returns.
Knute's right about blocking. There's more here about perceived
performance when loading an image here:
<http://java.sun.com/docs/books/tutorial/uiswing/components/icon.html>
Also, I'm suspicious of overriding the JFrame's paint() method
(inherited from Container), without calling super.paint():
<http://java.sun.com/javase/6/docs/api/java/awt/Component.html#paint(java
.awt.Graphics)>
Absent that, I saw nothing until I tabbed through the fields.
To focus on the FlowLayout aspect of the code, I changed to a JPanel,
which uses FlowLayout by default. I also used an ImageIcon to contain an
image. Sorry, I'm not familiar with the Chart API:
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import javax.swing.*;
public class GoogleDrawImage
{
public static void main(String[] args)
{
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(new ImagePanel());
frame.setTitle("Google Chart API");
frame.setSize(600, 300);
frame.setVisible(true);
}}
class ImagePanel extends JPanel implements ActionListener {
JTextField addressField, appendFieldcht, appendFieldchs,
appendFieldchd, appendFieldchm, appendFieldchf;
JLabel lbleGoogleInstr, lbleFieldcht, lbleFieldchs,
lbleFieldchd, lbleFieldchm, lbleFieldchf;
JButton btnGetGoogleApis, btnClose;
public ImagePanel() {
// Use default FlowLayout.
addressField = new JTextField(20);
addressField.setText("http://chart.apis.google.com...");
appendFieldcht = new JTextField(8);
appendFieldcht.setText("r");
appendFieldchs = new JTextField(8);
appendFieldchs.setText("400x400");
appendFieldchd = new JTextField(8);
appendFieldchd.setText("t:70,70,70,70,70,70");
appendFieldchm = new JTextField(8);
appendFieldchm.setText("B,FF0000,0,0,5");
appendFieldchf = new JTextField(8);
appendFieldchf.setText("c,s,000000");
lbleGoogleInstr = new JLabel("Complete these:");
lbleFieldcht = new JLabel("cht is: ");
lbleFieldchs = new JLabel("chs is: ");
lbleFieldchd = new JLabel("chd is: ");
lbleFieldchm = new JLabel("chm is: ");
lbleFieldchf = new JLabel("chf is: ");
btnGetGoogleApis = new JButton("GetGoogleApis");
btnGetGoogleApis.setActionCommand("GrabItAll");
btnGetGoogleApis.addActionListener(this);
btnClose = new JButton("Close Application");
btnClose.setActionCommand("close");
btnClose.addActionListener(this);
// Add Components to this container.
this.add(lbleGoogleInstr);
this.add(addressField);
this.add(lbleFieldcht);
this.add(appendFieldcht);
this.add(lbleFieldchs);
this.add(appendFieldchs);
this.add(lbleFieldchd);
this.add(appendFieldchd);
this.add(lbleFieldchm);
this.add(appendFieldchm);
this.add(lbleFieldchf);
this.add(appendFieldchf);
this.add(btnGetGoogleApis);
this.add(btnClose);
try {
ImageIcon icon = new ImageIcon(new URL(
"http://www.google.com/logos/olympics08_opening.gif"));
JLabel imageLabel = new JLabel(icon);
icon.setImageObserver(imageLabel);
this.add(imageLabel);
} catch (MalformedURLException e) {
System.err.println(e.toString());
}
}
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("close")) {
System.exit(0);
}
}
}
[I appreciate your sscce, but some might reasonably be wary of code that
reads from the network and writes to the file system.]
--
John B. Matthews
trashgod at gmail dot com
home dot woh dot rr dot com slash jbmatthews
Thanks for your responses. I have been unable to reconstruct the
program using panels. That rewrite of placing it on a panel makes none
of the labels and textfields appear reagrdless of which IDE I use. Yes
I did download John's sample above and it runs. but my adapting it to
my original one does not work. If I place the mouse over some of the
buttons they show up but nothing else shows up.
So I went back to my design written above with these revsions below.
image into the frame and immediately did a save. With a new revision
image/file.png, if I so desire. Each button click is has a try and a
catch.
This is not a good programming example, too quirky.