Question

Ex: In relation to image painting in frame, the following code is the use of getImage()...

Ex: In relation to image painting in frame, the following code is the use of getImage() in toolkit.
Modify the image() through ImageIcon and imageIO.read() of javax into a converted form using imageIO.read().

import java.awt.*;

import javax.swing.*;

public class FrameImage extends JPanel{

public void paint(Graphics g) {

Toolkit toolkit = Toolkit.getDefaultToolkit();

Image image = toolkit.getImage("image/grapes.gif");

g.drawImage(image, 60, 40, this);

}

public static void main(String[] args) {

JFrame frame = new JFrame();

FrameImage pannell = new FrameImage();

frame.add(pannell);

frame.setTitle("image paint");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.pack();

frame.setVisible(true);

}

}

Please solve the problem. and Please Let me explain the process.

Thank you:)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

// Dear student i have explained all program each steps using comment above the code this code is working good

and i attached the output screen shot at end of the program

import java.awt.Color;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;


// The class FrameImage is inheriting all the properties of JFrame
public class FrameImage extends JFrame {
  
   // this is used to add a label
  
   JLabel label;
     
   // created a default construct to load an image
   public FrameImage() throws IOException
   {
      
       // create an ojbect to JLabel class
   label=new JLabel("Hello world");  
  
   // this method is used to read an image
  
   BufferedImage wPic = ImageIO.read(this.getClass().getResource("image/road.jpg"));
  
   // this method display the image in Jlable icon
   JLabel wIcon = new JLabel(new ImageIcon(wPic));
  
   // this method makes the frame to visible
       this.setVisible(true);
      
      
       // this method sets the title
       this.setTitle("Frame Image");
      
      
       // this method is used to
       Container c=this.getContentPane();
      
       // this method is used to set the layout
       c.setLayout(new FlowLayout());
      
      
       c.add(label);
       c.add(wIcon);
      
       // it set the size of the window
       this.setSize(500,500);
      
       //this method closes the JFrame Operations
       this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      
   }

   public static void main(String[] args) throws IOException {
      

      
       // when we created and object to a class
      
       FrameImage fi=new FrameImage();
         
   }

}

Output:


Add a comment
Know the answer?
Add Answer to:
Ex: In relation to image painting in frame, the following code is the use of getImage()...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 2. Find the error(s), correct it, and write output. Point 5 package javaapplication154 import javax.swing.* import...

    2. Find the error(s), correct it, and write output. Point 5 package javaapplication154 import javax.swing.* import java.awt. import java.awt.Color publie class JGraphicsPanel extends JPanel f public JGraphiesPanel(Color color) f this.setBackground(color); public void paint(Graphies super.paint0; setColor(0,0,0); filloval(10, 5, 40, 40); fillOval(60, 5, 40, 40); package javaapplication154; import java.awt.Color; import javax.swing.JFrame; public class JavaApplication154 public static void main(Stringl) args) [ JFrame frame- new JFrame( "Using colors"); frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE); JGraphiesPanel GraphiesPanel-new JGraphiesPanel(Color.RED); frame.setSize( 400, 180); frame.setVisible );

  • tart from the following code, and add Action Listener to make it functional to do the...

    tart from the following code, and add Action Listener to make it functional to do the temperature conversion in the direction of the arrow that is clicked. . (Need about 10 lines) Note: import javax.swing.*; import java.awt.GridLayout; import java.awt.event.*; import java.text.DecimalFormat; public class temperatureConverter extends JFrame { public static void main(String[] args) {     JFrame frame = new temperatureConverter();     frame.setTitle("Temp");     frame.setSize(200, 100);     frame.setLocationRelativeTo(null);     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);     frame.setVisible(true); }    public temperatureConverter() {     JLabel lblC = new...

  • Add a timer to the lightbulb ON/OFF program such that the bulb stays on for 10...

    Add a timer to the lightbulb ON/OFF program such that the bulb stays on for 10 seconds after the ON button is pushed and then goes off.   Put a new label on the lightbulb panel that counts the number of seconds the bulb is on and displays the number of seconds as it counts up from 0 to 10. THIS IS A JAVA PROGRAM. The image above is what it should look like. // Demonstrates mnemonics and tool tips. //********************************************************************...

  • There 2 parts to complete: import javax.swing.*; import java.awt.event.*; import java.awt.*; public class Q4 extends JFrame...

    There 2 parts to complete: import javax.swing.*; import java.awt.event.*; import java.awt.*; public class Q4 extends JFrame { private int xPos, yPos; public Q4() { JPanel drawPanel = new JPanel() { @Override public void paintComponent(Graphics g) { super.paintComponent(g); // paint parent's background //complete this: } }; drawPanel.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { //complete this :- set the xPos, yPos }    }); setContentPane(drawPanel); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setTitle("Mouse-Click Demo"); setSize(400, 250); setVisible(true); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() {...

  • The program given here will draw the Olympic logo. Modify the program as the following: 1.Change...

    The program given here will draw the Olympic logo. Modify the program as the following: 1.Change the class name to Test1OlympicYourFirstNameYourLastName 2.Change the OlympicRingPanel class name to OlympicRingPanelYourfirstNameYourLastName 3.Modify the program so that the first ring will be filled with random color with a random alpha value. I have shown 3 sample output here for your references. 4.Modify the paintComponent so your name will be displayed under the Olympic rings.The color of your name should be random color as well....

  • This is the java GUI program. I want to add an icon to a button, but...

    This is the java GUI program. I want to add an icon to a button, but it shows nothing. Can you fix it for me please? import java.awt.BorderLayout; import java.awt.Container; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; class Icon extends JFrame{ public static void main(String args[]){ Icon frame = new Icon("title"); frame.setVisible(true); } Icon(String title){ setTitle(title); setBounds(100, 100, 300, 250); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel p = new JPanel(); ImageIcon icon1 = new ImageIcon("https://static.thenounproject.com/png/610387-200.png"); JButton button1 = new JButton(icon1); p.add(button1); Container contentPane...

  • Basic button tracking Deliverables Updated files for app6.java myJFrame6.java myJPanel6.java student.java Contents You can start with...

    Basic button tracking Deliverables Updated files for app6.java myJFrame6.java myJPanel6.java student.java Contents You can start with the files available here. public class app6 { public static void main(String args[]) {     myJFrame6 mjf = new myJFrame6(); } } import java.awt.*; import javax.swing.*; import java.awt.event.*; public class myJFrame6 extends JFrame {    myJPanel6 p6;    public myJFrame6 ()    {        super ("My First Frame"); //------------------------------------------------------ // Create components: Jpanel, JLabel and JTextField        p6 = new myJPanel6(); //------------------------------------------------------...

  • Can someone modify my code so that I do not get this error: Exception in thread...

    Can someone modify my code so that I do not get this error: Exception in thread "main" java.lang.NullPointerException at java.awt.Container.addImpl(Container.java:1043) at java.awt.Container.add(Container.java:363) at RatePanel.<init>(RatePanel.java:64) at CurrencyConverter.main(CurrencyConverter.java:16) This code should get the amount of money in US dollars from user and then let them select which currency they are trying to convert to and then in the textfield print the amount //********************************************************************* //File name: RatePanel.java //Name: Brittany Hines //Purpose: Panel for a program that convers different currencyNamerencies to use dollars //*********************************************************************...

  • Program #2 Write a program to simulate showing an NBA Team on a Basketball court Here...

    Program #2 Write a program to simulate showing an NBA Team on a Basketball court Here is an example of the screenshot when running the program: Tony Parker T. Splitter T. Duncan M. Gineb Player Kame: M Ginobil Player Age 2 Add A Player Ce An example of the JFrame subclass with main method is as follows import java.awt. import java.awt.event." import javax.swing. public class NBA Playoff extends JFrame private JTextField txtName: private JTextField txtAge: private NBATeam spurs private NBAcourtPanel...

  • Stick to the template which is provided on below and just change the //TODO part, please....

    Stick to the template which is provided on below and just change the //TODO part, please. Template Lab13.java package lab13; import javax.imageio.ImageIO; import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.io.IOException; public class Lab13 {    public static void main (String[] args) {        JFrame frame = new SmileyFrame();        frame.add(new SmileyPanel());        frame.setVisible(true);    } } class SmileyFrame extends JFrame {    private static final long serialVersionUID = 7613378514394599117L;    private static final int WIDTH = 400;...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT