cameron fraser

Greenhorn
+ Follow
since Jun 11, 2016
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by cameron fraser

You said "You are attempting to load the image inside paintComponent(). This is not the place to do it."

Could you type out some code I could paste in to display the image? A bit over my head right now.
8 years ago


Not sure if I am doing the last parameter correctly, I am following other examples, but I am getting an error:

Multiple markers at this line
- Line breakpoint:SimpleGuiB [line: 23] - test()
- The method drawImage(Image, int, int, ImageObserver) in the type Graphics is not applicable for the arguments (String, int, int,
SimpleGuiB)

8 years ago
Ahh, I removed it from there. Would I create a custom method for it? I tried it in the go() method but it wont load there either. Any suggestions?

I did have some paintcode just didnt want to complicate and divert attention to it.
8 years ago
Oh, sorry forgot to mention.

Got it to get past the exception error with a new image link with two slashes "//" but the JFrame its supposed to display the image on is just blank.

Any ideas?

Full code:

public class SimpleGuiB extends JPanel implements ActionListener {
JButton button;

public static void main (String[] args) {
SimpleGuiB gui = new SimpleGuiB();
gui.go();
}

public void go(){
SimpleGuiB gui = new SimpleGuiB();
JFrame frame = new JFrame();

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(970, 600);
frame.setVisible(true);
frame.add(gui);
}

public void paintComponent(Graphics g){

URL test;
try {
test = new URL("https://timedotcom.files.wordpress.com/2015/01/trump.jpg");
Image image = new ImageIcon(test).getImage();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
8 years ago
Ive been following my book on ImageIcons but decided to try out a URL:



Can anyone explain why this is not working or give me a tip on how I can?

Thank you.
8 years ago
Can someone explain what exactly is going on in this statement?

Sequencer sequencer = MidiSystem.getSequencer();

Am I thinking correctly about this statement? You are creating a reference variable called "sequencer" to the Sequencer Interface, yet its calling a method?

I am understanding of object creation and polymorphism such as: Sequencer sequencer = new Sequencer(); or Animal a = new lizard(); But here I am a bit confused to what is going on.

8 years ago