473,626 Members | 3,353 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to fill / put an image of jpeg into a Reatangle in the code below



i have a java project to do , but what problem i encounter is how to fill /
put an image of jpeg into a Reatangle in the code below

please type the code in detail since i am an entry level students
thanks a lot
the code Listed below
// ManyRectangle.j ava
// Chapter 4
// M. Laszlo

import java.awt.*;
import javax.swing.*;
import java.awt.geom.* ;
import banana.*;

public class PaintManyRectan gles extends ApplicationPane l {

public PaintManyRectan gles() {
setBackground(C olor.black);
}

public static void main(String[] args) {
parseArgs(args) ;
ApplicationPane l panel = new PaintManyRectan gles();
ApplicationFram e frame = new ApplicationFram e("Many Rectangles");
frame.setPanel( panel);
panel.makeConte nt();
frame.show();
}

protected static int nbrRectangles = 100;
protected static int minLength = 100, maxLength = 200;

public static void parseArgs(Strin g[] args) {
if ((args.length == 2) || (args.length > 3)) {
System.out.prin tln("USAGE: java PaintManyRectan gles [n [minLen
maxLen]]");
System.exit(1);
}
if (args.length > 0)
nbrRectangles = Integer.parseIn t(args[0]);
if (args.length > 2) {
minLength = Integer.parseIn t(args[1]);
maxLength = Integer.parseIn t(args[2]);
}
}

protected RectangleGeomet ry[] rectangles;

public void makeContent() {
// construct a random rectangle generator rndRect
Dimension d = getFrame().getC ontentSize();
Range frameWidth = new Range(0, d.width);
Range frameHeight = new Range(0, d.height);
RandomRectangle rndRect =
new RandomRectangle (frameWidth, frameHeight);
// set rndRect's width and height properties
Range minMaxLengths = new Range(minLength , maxLength);
rndRect.setWidt hRange(minMaxLe ngths);
rndRect.setHeig htRange(minMaxL engths);
// generate and save random rectangles
rectangles = new RectangleGeomet ry[nbrRectangles];
for (int i = 0; i < nbrRectangles; i++)
rectangles[i] = rndRect.nextRec tangle();
}

public void paintComponent( Graphics g) {
super.paintComp onent(g);
Graphics2D g2 = (Graphics2D)g;
RandomColor rndClr = new RandomColor();
for (int i = 0; i < rectangles.leng th; i++) {
g2.setPaint(rnd Clr.nextColor() );
RectangleGeomet ry r = rectangles[i];
g2.fill(r.shape ());
}
}
}
Jul 17 '05 #1
1 2142
"samlicon" <sa******@mail. hongkong.com> wrote in
news:41******** **@rain.i-cable.com:


i have a java project to do , but what problem i encounter is how to
fill / put an image of jpeg into a Reatangle in the code below

please type the code in detail since i am an entry level students
thanks a lot


Maybe look at the IconImage class?
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
13067
by: Gregory | last post by:
Hello, I'm trying to do the above in order to process an image and return the result to an html image control. It fails and my key suspects are either the variable that I'm passing in - ImageName - for processing, or the return data which is done (or not as the case may be) by imagejpeg($img) in the script, after header("Content-type: image/jpeg"). Any insights would be most welcome, especially debugging techniques and a pointer to...
0
1796
by: doffer | last post by:
I want to make a portfoliosystem where user can register and get their own portfolio... I've started the developer work, but I'm stuck on the image upload part... I'm experiencing some problems getting the picture resized and thumbnailed... I'm on a apache server running php 5 with 8MB php_memory. When uploading, the script works fine most times when uploading small files (below 100kb and sometimes up close to 300kb too), but when...
1
5401
by: Daniel | last post by:
I have looked everywhere on the web for an answer to this and the only thing I can find is converting the image format when the file is present on the local filesystem. What I want to do is use a web form to upload a TIFF image (scanned images) and convert it to a JPEG before I insert it into SQL Server. The file upload part works great, but I can;t convert the image. I certainly don't want to upload it the the server filesystem, convert...
13
2345
by: Neo Geshel | last post by:
I have examined about 80+ different upload scripts on the 'net, both in VB and C#, and none seem to do what I need them to do. Perhaps someone here can point me somewhere that Google hasn't reached yet (I have gone all the way to page 50 on Google's results!!). Here are my requirements: • I have a DataGrid. Everything will be done from here. Everything. No exceptions. Everything will also be done in VB, without any code-behind to...
15
5329
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the path of the uploaded image, and resize it with the provided dimensions. My function is below. The current function is returning an error when run from the upload function: A generic error occurred in GDI+. Not sure what exactly that means. From what...
4
3462
by: LT.Ang | last post by:
I am developing an application that possibly opens very large images - bmp, jpeg, tiff. I have 2 questions: Language: C#, VS .NET 2003. 1. When the program opens a BMP image, the amount of memory used seems to be larger for BMP files than JPEGs with the same pixel dimensions. For example, 5200 x 5000 pixels image -- increase in Mem Usage is about 80MB for JPEG, but 200MB for BMP (with Task Manager). The Mem Usage is noted before and...
23
5913
by: Peter | last post by:
I have a problem with a page show_image.asp that returns a jpg image under Windows XP Pro SP2. The page sets content type as: Response.ContentType = "image/jpg" While this works perfectly fine on most machines, on some machines I experience this problem: When loading the page a window pops up that asks if I want to open the document show_page.asp. When I click "Open" Interdev pops up and opens up a
1
1964
by: spgedwards | last post by:
I am trying to run a basic script that displays an existing jpeg image and writes some text over it. Sounds simple, but I cannot seem to be able to colour the font correctly. In the example below it should be black but it comes out orange. In fact, even if I change the colour to 0, 0, 255 it's orange. I've read in the PHP documentation (the user contributed notes) that there are issues with jpeg font colouring. But I've not seen any...
5
5751
by: Steve | last post by:
Hi all Does anybody please know a way to extract an Image from a pdf file and save it as a TIFF? I have used a scanner to scan documents which are then placed on a server, but I need to extract the image of the document (just the first page if there are multiple pages) and save it as a TIFF so I can then use the Tesseract OCR to get the text in the image.
0
8265
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8196
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8705
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8637
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8364
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4092
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4197
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1808
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.