Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Why is my logo.png so large? Can someone fix it to make it smaller? Code: import

ID: 3889298 • Letter: W

Question

Why is my logo.png so large? Can someone fix it to make it smaller?

Code:

import java.text.DecimalFormat;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
public class TuitionCost{
public static void main(String[] args) {
int costCredits;
int student;
String input;
double a;
DecimalFormat dollar = new DecimalFormat("#,##0.00");
final ImageIcon icon= new ImageIcon("logo.png");
JOptionPane.showMessageDialog(null, "North Hennepin Community College", "Tuition Costs at NHCC", JOptionPane.INFORMATION_MESSAGE);
String[] options={"1","2"};
input = (String) JOptionPane.showInputDialog(null,"Are you taking: 1 - on-campus and/or hybrid courses 2 - online courses Please enter 1 or 2:","Input", JOptionPane.QUESTION_MESSAGE, icon, options, icon);
double[] rates = {184.17,193.85};
student = Integer.parseInt(input);
if(student > 0 && student < 4){
input = JOptionPane.showInputDialog(null, "How many credits are you taking?", JOptionPane.QUESTION_MESSAGE);
costCredits = Integer.parseInt(input);
if(costCredits != 0){
a = costCredits * rates[student-1];
float textBookCosts=(float)320.50;
JOptionPane.showMessageDialog(null, dollar.format(costCredits) + " credits at $" + rates[student-1] + " per semester yields a tuition of $" + dollar.format(a)+" Textbooks cost=$"+textBookCosts);
}else{
JOptionPane.showMessageDialog(null, "Credits cannot be zero.", "Invalid Input", JOptionPane.ERROR_MESSAGE);
}
System.exit(0);
}else {
JOptionPane.showMessageDialog(null, "You must enter a 1 or 2. Please Run the program again.", "Invalid Input", JOptionPane.ERROR_MESSAGE);
}
}
}

Explanation / Answer

1. One way of doig it is resize the "logo.png" resource where it is stored .

If it is not available then you may resize it within the code , except that icon cannot be made final

2. Add an import : import java.awt.Image; // For resize function

and change : final ImageIcon icon= new ImageIcon("logo.png"); to the following

ImageIcon ic = new ImageIcon("logo.png"); // Load in temproary variable

Image image = ic.getImage().getScaledInstance(50, 50, java.awt.Image.SCALE_SMOOTH); // Transform // Here the numbers 50 , 50 decide the size and can be increased or decreased as per your need

final ImageIcon icon = new ImageIcon(image); // Load to icon variable

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote