Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Creating a scaleUp main method in a new class

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Creating a scaleUp main method in a new class

    So I'm trying to create a class with a method called ScaleUp which basically scales a .jpg file by a certain amount. So far I have:

    import java.util.*;
    public class ScaleUp
    {                 
    public static void main(String[] args) {
      /*  HERE FROM PREVIOUS ATTEMPT:*/
       Scanner sc = new Scanner(System.in);
       System.out.print("File: ");
      String fileShortName = sc.next();
      String fileName = "/C:/Users/Umar/Desktop/Comp Sci/Dr. Java Add Ons/mediasources/" +
      fileShortName + ".jpg";
      System.out.print("Scale: ");
      int numTimes = sc.nextInt(); 
      Picture pictObj = new Picture(fileName);
     
    }
    public static Picture scaleUp(int numTimes)
      {
      String fileName = FileChooser.pickAFile();
      Picture origPic = new Picture(fileName);
     
        Picture targetPicture = 
          new Picture(origPic.getWidth() * numTimes,
                      origPic.getHeight() * numTimes);
        Pixel sourcePixel = null;
        Pixel targetPixel = null;
        int targetX = 0;
        int targetY = 0;
     
        for (int sourceX = 0;
           sourceX < origPic.getWidth();
           sourceX++)
        {
            for (int sourceY=0;
            sourceY < origPic.getHeight();
            sourceY++)
        {
              sourcePixel = origPic.getPixel(sourceX,sourceY);
     
           for (int indexY = 0; indexY < numTimes; indexY++)
          {
             for (int indexX = 0; indexX < numTimes; indexX++)
            {
              targetX = sourceX * numTimes + indexX;
              targetY = sourceY * numTimes + indexY;
              targetPixel = targetPicture.getPixel(targetX,
                                                   targetY);
              targetPixel.setColor(sourcePixel.getColor());
            }
          }
        }
      }
     
      return targetPicture;
     
    }
     
    }

    However, when I run the program I can use scanner to input information it accepts the info but no picture file is shown. Can someone please show me how I can get the program to actually spit out the picture that the method is invoked on?


  2. #2
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: Creating a scaleUp main method in a new class

    First get your terminology straight. You don't scale a file. You can scale an image. It's not relevant to the scaling what type of file the image was read from.

    Your code uses Picture and Pixel classes which are not part of the standard JDK and which we know nothing about. You need to seek help wherever you got the classes from.

    db

Similar Threads

  1. how to execute a simple display without a main method
    By chronoz13 in forum Java Theory & Questions
    Replies: 5
    Last Post: January 13th, 2010, 07:28 AM
  2. Calling a void method into a static void main within same class
    By sketch_flygirl in forum Object Oriented Programming
    Replies: 3
    Last Post: November 15th, 2009, 05:24 PM
  3. Main Class Not Found Problem
    By shadow in forum Java Theory & Questions
    Replies: 3
    Last Post: September 29th, 2009, 09:42 AM
  4. could not find the main class
    By Tisofa in forum Object Oriented Programming
    Replies: 1
    Last Post: September 27th, 2009, 02:58 AM
  5. adding main method to a code
    By IDK12 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: August 31st, 2009, 08:52 PM