studio.jpg Il jar si apre mostrando l'immagine di fianco, ma mi domando come mai essendo 4 Kb impiega un bel pò di secondi per aprirsi. E' possibile ottimizzare qualcosa? Sarà il fatto che le icone vanno prima scaricate dall'URL e poi ridimensionate?
codice:public class MyProgram { private String pathjava= "C:\\Users\\Paolo\\Desktop\\jjj.gif"; private URL pathpython= new URL("http://screenshot.it.sftcdn.net/it/scrn/69000/69838/python-20.jpg"); private URL pathmips= new URL("https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcQi_VaanDQyfTAph9BNO0NF7sN9ZR4Ven9LM9W_uiBbAYc5oVq7Pg"); private URL pathenglish= new URL("http://upload.wikimedia.org/wikipedia/commons/3/3a/English_Speech_balloon.png"); public MyProgram() throws MalformedURLException{start();}; public void start() throws MalformedURLException{ JFrame f = new JFrame("STUDIO"); f.setSize(new Dimension(240,260)); //dimensioni frame f.setLocation(300, 300); //locazione frame Container c = f.getContentPane(); JPanel panel = new JPanel(); panel.setBackground(new Color(1)); c.add(panel); Image im = new ImageIcon(pathjava).getImage(); im = im.getScaledInstance(100, 100, Image.SCALE_DEFAULT); //riscalatura immagine ImageIcon java = new ImageIcon(im); Image im2 = new ImageIcon(pathpython).getImage(); im2 = im2.getScaledInstance(100, 100, Image.SCALE_DEFAULT); ImageIcon python = new ImageIcon(im2); Image im3= new ImageIcon(pathmips).getImage(); im3 = im3.getScaledInstance(100, 100, Image.SCALE_DEFAULT); ImageIcon mips = new ImageIcon(im3); Image im4 = new ImageIcon(pathenglish).getImage(); im4 = im4.getScaledInstance(100, 100, Image.SCALE_DEFAULT); ImageIcon english = new ImageIcon(im4); JButton j = new JButton(java); JButton p = new JButton(python); JButton m = new JButton(mips); JButton e = new JButton(english); j.setPreferredSize(new Dimension(100,100)); //dimensioni del bottone p.setPreferredSize(new Dimension(100,100)); m.setPreferredSize(new Dimension(100,100)); e.setPreferredSize(new Dimension(100,100)); panel.add(j); //aggiunge i bottoni al pannello panel.add(p); panel.add(m); panel.add(e); f.setVisible(true); // mostra il frame } public static void main(String[] args) throws MalformedURLException { new MyProgram(); } }


Rispondi quotando