Tuesday 15 September 2015

java - Gif not showing up in JFrame -



java - Gif not showing up in JFrame -

i'm trying gif appear on 1 of jframe , programme compiles doesn't show gif want show. matter of have gif stored on computer?

import javax.swing.*; import java.awt.*; import java.util.*; public class iworkoutscreen { public void iworkoutscreen() { string calories = "this many"; this.setbackground(color.white); this.setlayout(new borderlayout()); this.setpreferredsize(new dimension(800, 400)); this.pack(); jbutton button = new jbutton("press start workout"); this.add(button, borderlayout.page_start); jlabel timer = new jlabel("this timer better"); timer.setpreferredsize(new dimension(400, 10)); imageicon timericon = new imageicon("7tak4g8ta.gif"); timer.seticon(timericon); this.add(timer, borderlayout.center); button = new jbutton("button 3 (line_start)"); this.add(button, borderlayout.line_start); button = new jbutton("long-named button 4 (page_end)"); this.add(button, borderlayout.line_end); jlabel caloriesburned = new jlabel("you have burned " + calories + " calories!!"); this.add(caloriesburned, borderlayout.page_end); } }

the next mcve works. not alter method constructor, corrects other problems. hot-links image should work anyone.

import java.awt.*; import java.net.malformedurlexception; import java.net.url; import javax.swing.*; public class iworkoutscreen extends jframe { public iworkoutscreen() throws malformedurlexception { string calories = "this many"; this.setbackground(color.white); this.setlayout(new borderlayout()); jbutton button = new jbutton("press start workout"); this.add(button, borderlayout.page_start); jlabel timer = new jlabel("this timer better"); imageicon timericon = new imageicon( new url("http://i.imgur.com/t8x0i29.png")); timer.seticon(timericon); this.add(timer, borderlayout.center); button = new jbutton("button 3 (line_start)"); this.add(button, borderlayout.line_start); button = new jbutton("long-named button 4 (page_end)"); this.add(button, borderlayout.line_end); jlabel caloriesburned = new jlabel( "you have burned " + calories + " calories!!"); this.add(caloriesburned, borderlayout.page_end); this.pack(); } public static void main(string[] args) { runnable r = new runnable() { @override public void run() { seek { jframe f = new iworkoutscreen(); f.setlocationbyplatform(true); f.setvisible(true); } grab (malformedurlexception ex) { ex.printstacktrace(); } } }; swingutilities.invokelater(r); } }

java swing gif embedded-resource imageicon

No comments:

Post a Comment