Help -- vectors
i am writing an editor and i have run into a problem.
I am using vectors to keep track of the documents that
opened. the documents are displayed in a JTabbedPane
and i am using a JTextArea for editing them. When i
try to do go to Select All of i get a bunch of errors.
here is code that i am using to: add elements to the
Vector, trying to Select All. And the runtime error
that occurs when i try the select All on anything but
the first element in the Vector.
adding elements to the Vector:
vector = new Vector();
vector.addElement(new JTextArea());
((JTextArea)vector.lastElement()).setTabSize(2);
((JTextArea)vector.lastElement()).setText(text);
JScrollPane scrollPane = new
JScrollPane((JTextArea)vector.lastElement());trying to selectAll:
((JTextArea)vector.elementAt(tabbedPane.getSelect
dIndex())).selectAll();error:
Exception occurred during event dispatching:
java.lang.ArrayIndexOutOfBoundsException: 1 >= 1
at java.util.Vector.elementAt(Vector.java:417)
at
VisualChange$ItemHandler.actionPerformed(VisualChange.
ava:589)
at
javax.swing.AbstractButton.fireActionPerformed(Abstrac
Button.java:1450)
at
javax.swing.AbstractButton$ForwardActionEvents.actionP
rformed(AbstractButton.java:1504)
at
javax.swing.DefaultButtonModel.fireActionPerformed(Def
ultButtonModel.java:378)
at
javax.swing.DefaultButtonModel.setPressed(DefaultButto
Model.java:250)
at
javax.swing.AbstractButton.doClick(AbstractButton.java
279)
at
javax.swing.plaf.basic.BasicMenuItemUI$MouseInputHandl
r.mouseReleased(BasicMenuItemUI.java:886)
at
java.awt.AWTEventMulticaster.mouseReleased(AWTEventMul
icaster.java:230)
at
java.awt.Component.processMouseEvent(Component.java:37
7)
at
java.awt.Component.processEvent(Component.java:3546)
at
java.awt.Container.processEvent(Container.java:1164)
at
java.awt.Component.dispatchEventImpl(Component.java:25
5)
at
java.awt.Container.dispatchEventImpl(Container.java:12
3)
at
java.awt.Component.dispatchEvent(Component.java:2499)
at
java.awt.LightweightDispatcher.retargetMouseEvent(Cont
iner.java:2451)
at
java.awt.LightweightDispatcher.processMouseEvent(Conta
ner.java:2216)
at
java.awt.LightweightDispatcher.dispatchEvent(Container
java:2125)
at
java.awt.Container.dispatchEventImpl(Container.java:12
0)
at
java.awt.Window.dispatchEventImpl(Window.java:912)
at
java.awt.Component.dispatchEvent(Component.java:2499)
at
java.awt.EventQueue.dispatchEvent(EventQueue.java:319)
at
java.awt.EventDispatchThread.pumpOneEvent(EventDispatc
Thread.java:103)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchT
read.java:93)
at
java.awt.EventDispatchThread.run(EventDispatchThread.j
va:84)
sample code would help a lot. thanks in
advance: TravenE.
i hope this is as simple as i think it is.. is this the EXACT code youre using to add new elements: ???
vector = new Vector();
vector.addElement(new TextArea());
((JTextArea)vector.lastElement()).setTabSize(2);
((JTextArea)vector.lastElement()).setText(text);
JScrollPane scrollPane = new> JScrollPane((JTextArea)vector.lastElement());"""
cause, what i think is happening, is that youre just creating the new vector each time youre attempting to add elements to it..youre basically deleting the elements in the vector every time you add a new element, so the most elements you can have is one... try this: move the following line:
" vector = new Vector();"
move it somewhere else...like in the form constructor or somewhere where it will only execute ONCE.. because right now, you have the vector redefining itself every time a new element is being added.
anyway, hope it works... sorry if i misread your code. talk to ya later,
Steven Berardi
Similar Messages
-
Newbie question. help vector add
hi group
i have this problem:
valoresindex.add(1, val);
for (int i=2; i<numColumns; i++) {
valoresindex.add(i,rs.getString(i));
System.out.println((String)valoresindex.get(i));
the error it is:
Error al leer archivojava.lang.ArrayIndexOutOfBoundsException: 1 > 0
help please.You are trying to add an item to the '1' index, but there are no items in the Vector yet. If you want to add items to a Vector one after the other, just use add (Object o). There is no need to specify an index.
Secondly, the items in a Vector start at the '0' index, not '1'. -
Help, vector files pixilated
I have a problem trying to upload a vector logo created in
illustrator and saved as gif file to preserve transparency. But it
turns out pixiliated not just on the web but also in illustrator.
With transparency it should work fine, and has before but the file
becomes pixilated -
http://www.jentespranget.no
(logo in centre)
Any ideas how to solve this please?
Cheers"Stagtime" <[email protected]> wrote in
message
news:[email protected]...
>I have a problem trying to upload a vector logo created
in illustrator and
> saved as gif file to preserve transparency. But it turns
out pixiliated
> not
> just on the web but also in illustrator. With
transparency it should work
> fine,
> and has before but the file becomes pixilated -
>
>
http://www.jentespranget.no
(logo in centre)
>
> Any ideas how to solve this please?
well, you need to understand the difference between vector
and raster images
and how they deal with transparencies. Simply put, your
vector file is
really just a bunch of math - nodes define points that have
lines or bezier
curves between them. If they're closed objects, they can
contain a fill
color, but again, that's all still just math stuff that gets
translated to
the screen and gets retranslated when you zoom in/out. The
vector files are
non-lossy.
Raster files, which are any bitmaps, are mosaics, and
depending on the file
format, they're lossy. Each pixel must have a defined color.
If in your
working file (say a PSD, CPT, or Fireworks PNG) you have a
bunch of
objects/layers, the curves of said object are simulated by
varying the
transparency of individual pixels to show the color of the
layer
below/background. This is called anti-aliasing and is
necessary because when
you're dealing with something that is just a mosaic of square
tiles, there
can be no angles other than right angles (90 degrees).
Anything other than
90 degrees must be simulated.
The GIF format can do transparency two ways: by a single
specific color or
via a mask (and really the mask just basically then makes the
masked area
black and uses that single color for the transparency color).
Lets say in
your original file your background color is lime green and
your object is a
neon orange circle and you select the green as your
transparency color. That
*single* shade of green will be transparent, BUT since a GIF
must be
"flattened", i.e. no layers, the anti-aliasing of the "round"
angles of the
circle (which are of varying transparent levels) are showing
quite a few
more shades of green and that will give you that "halo" of
another color -
there's no escaping that, really.
Your options are to make the background color of the GIF file
the same color
as the background of your web page (and if you are changing
background
colors left and right, well, you would need to make GIF files
for each one
of those colors), or you could save the file off as a PNG
which has the
ability to handle an alpha mask and do true transparency.
However, you'll
have to do some browser conditional hacks for IE versions 6
and below to see
this transparency. -
import java.util.*;
public class usingVectors
static Scanner console = new Scanner(System.in);
public static void main(String[] args)
int VECTOR_SIZE;
System.out.print("Enter the size of the array: ");
VECTOR_SIZE = console.nextInt();
System.out.println();
Vector<Integer> listA = new Vector<Integer>();
System.out.print("Enter " + VECTOR_SIZE + " integers: ");
fillArray(listA, VECTOR_SIZE);
System.out.println();
System.out.print("List of Integers that you inputted: \n ");
printArray(listA, VECTOR_SIZE);
System.out.println();
System.out.println("The position of the smallest integers in the array is: " + indexSmallest(listA, VECTOR_SIZE));
System.out.println("The smallest integer in the array is: " + listA[indexSmallest(listA, VECTOR_SIZE)]);
public static void fillArray(int list, int sizeOfVector)
int index;
for (index = 0; index < sizeOfVector; index++)
list[index] = console.nextInt();
public static void printArray(int list, int sizeOfVector)
int index;
for (index = 0; index < sizeOfVector; index++)
System.out.print(list[index] + " ");
public static int indexSmallest(int list, int sizeOfVector)
int index;
int smallIndex = 0;
for (index = 0; index < sizeOfVector; index++)
if (list[smallIndex] > list[index])
smallIndex = index;
return smallIndex;
Im trying to pass a vector to a method. Im not sure what i am doing wrong if anyone could look at what im doing wrong i would appreciate it.
ER:usingVectors.java:19: fillArray(int,int) in usingVectors cannot be applied to (java.util.Vector<java.lang.Integer>,int)
fillArray(listA, VECTOR_SIZE);My first problem was to write a method, smallestIndex that takes as its parameters an int array and its size. Return the smalles element in the array and its postion. Now i have that done and it was good. He wants us to change that program to use vectors. So i feel like i have done most of it right but like you said the error. It won't pass the vector through to the method. I believe
ok thank you. I guess what i should ask you now. In my line of code. How do i set the parameters to pass a Vector instead of the int?
THANK YOU FOR YOU HELP
Vector<Integer> listA = new Vector<Integer>();
System.out.print("Enter " + VECTOR_SIZE + " integers: ");
fillArray(listA, VECTOR_SIZE); **This is where i call my method with the vector name listA, and the int VECTOR_SIZE, it pops the problem here or would it be in the declaring the new varibles at the start of the method**
System.out.println();
System.out.print("List of Integers that you inputted: \n ");
printArray(listA, VECTOR_SIZE);
System.out.println();
System.out.println("The position of the smallest integers in the array is: " + indexSmallest(listA, VECTOR_SIZE));
System.out.println("The smallest integer in the array is: " + listA[indexSmallest(listA, VECTOR_SIZE)]);
public static void fillArray(int list, int sizeOfVector) *Or would it be here?*
int index;
for (index = 0; index < sizeOfVector; index++)
list[index] = console.nextInt();
} -
J2ME WTK- Preveify Error- HELP!
I am developing a cell phone application in which I use Integer.parseInt(String s) and the Integer constructor Integer(int i), but I have come across this preverification error and I have no idea how to correct it:
Error preverifying class Integer
java/lang/VerifyError:
com.sun.kvem.ktools.ExecutionException: Preverifier returned 1
If anyone could give me a hint as to what this means that would be very helpful.
Before I got this error, I was inserting the jdk version of Integer into my /src/ file because I wanted to use the constructor Integer(String s) which is not supplied in the cldc version. After noticing I could parse the string and just use the cldc constructor, I deleted out the jdk Integer.java file. This is when the preverification error surfaced.
these are the lines of code that I use Integer if it helps:
vector.addElement(new Integer(Integer.parseInt(string)));
vector.addElement(new Integer(recordStore.getNextRecordID()));
someInt = ( (Integer)(vector.elementAt(index)) ).intValue();
ThanksNEVERMIND
Turns out all you have to do is in WTK go Project -> Clean. I hope this helps someone else. -
Serious Issues in Illustrator CS6, Expand and Snapping problems
Hi, my friends and fellow vector fanatics, we all love Adobe Illustrator and we like to work with this tool, and being a user since version CS3 I really like the new look and feel of CS6 however I noticed some issues when I am doing the following:
when I use pathfinder to expand objects they look weird like in this photo
you can notice the change in the r and also the a they changed shape
this is completly un acceptable, since the design has to be very precise
second issue is when I am trying to move an object it snaps to something I don't know if its a grid or not and I have checked off snapping to grid but still all objects snaps.
please I am eager to solve these problems and I am looking forward for your help.
thank you all for you cooperationHi All,
Just thought id add this also to the forum just incase you dont want to keep going back and unticking the Align to Pixel Grid option box. If you want it off completely, then go to the small arrow (far right of the transform palette) and turn off Align New Objects To Pixel Grid. Then things wont snap everytime you create a new shape or add guides etc..hope that helps vector buddies
Chris . -
Setting column names in JTable
can n e one tell me how to set column names for JTable..
i don't wanna use the JTable constructor ... cuz
my column names change...this is how i did it once...hope it helps
Vector columnNames = new Vector();
JTable previewTable = new JTable();
previewTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
previewScrollPane.getViewport().add(previewTable, null);
int colNo = 2; // i am displaying 2 columns
columnNames.add("Col One");
columnNames.add("Col Two");
String[] tableColumnNames = {"Id Name","Type"};
DefaultTableModel aModel = (DefaultTableModel) previewTable.getModel();
aModel.setColumnIdentifiers(tableColumnNames);
//add data to the table
.//loop
aModel.addRow(objects);
previewTable.revalidate();
previewTable.setModel(aModel); -
hello guys can any expret help me to do my project the dead line is sunday
please help [email protected]
NOTE:the program is just simple input output throw ms-dos
thank you :D
Project Description
This project is about developing a software for flight reservation system. This program uses three classes Flight, RouteInfo and Passenger.
Flight class:
Instance variables
flight number
name of airline
day of flying
Constructor
Initializes instance variables
Methods
getFlightNumber()
getNameOfAirline()
getDayOfFlying()
setFlightNumber()
setNameOfAirline()
setDayOfFlying()
toString()
Passenger class:
Instance variables
computernumber
name
telephone
source
destination
day of Flying
Constructor
Initializes name and telephone
Methods
getName()
getID()
getSource()
getDestination()
getDayOfFlying()
setName()
setID()
setSource()
setDestination()
setDayOfFlying()
toString()
RouteInfo Class:
Instance variables
flight number
source
destination
Constructor
Initializes instance variables
Methods
getFlightNumber()
getSource()
getDestination()
setFlightNumber()
setSource()
setDestination()
toString()
The program reads the following information from the file Flight.txt and creates array of Flight objects and initializes it. This is a fixed array.
Flight.txt
SV707#Saudi Arabian Airlines#Friday
SV611#Saudi Arabian Airlines#Monday
SV555#Saudi Arabian Airlines#Saturday
GA111#Gulf Air#Tuesday
GA222#Gulf Air#Monday
GA333#Gulf Air#Wednesday
EA523#Egypt Air#Sunday
EA555#Egypt Air#Thursday
The program reads the following information from the file Routes.txt and creates array of RouteInfo objects and initializes it. (For simplicity, leave the item Time of flying)
Routes.txt
SV707#Dammam#Madina
SV707#Madina#Dammam
SV611#Madina#Jeddah
SV611 #Jeddah#Madina
SV555#Dammam#Jeddah
SV555#Jeddah#Dammam
GA111#Jeddah#Bahrain
GA111#Bahrain#Madina
GA222#Bahrain#Jeddah
GA222#Madina#Bahrain
GA333#Bahrain#Taif
GA333#Taif#Bahrain
EA523#Cairo#Madina
EA555#Madina#Cairo
The program has the following commands:
Command Purpose
s Search availability: This needs parameters: the day, source and destination, and list all the flights available for the given criteria.
For example:
To search all flights on Friday from dammam to madinah: s f dammam madinah
b Book a flight: This needs passenger info, source destination and day of flying, reserves the seat and generate a unique computer number if the seat is available. Modification done in Passenger array itself.
For example:
b Ali,Muhammad Hasan 050889977 dammam madinah f
means the system is trying to make a reservation for Muhammad Hasan Ali,
phone 050889977 from Dammam to madinah on Friday.
z List all passengers name (based on source & destination): This should List Flights name and passengers name based on given source & destination.
For example:
To know passengers who have booked in a flight SV707 from dammam madinah:
z sv707 dammam madinah
c Cancel Booking: This should cancel a booking by reading passenger info, source destination and day of flying OR by reading a computer number only. Modification done in Passenger array.
for example:
c 1234567
c Ali,Muhammad Hasan 050889977 dammam madinah f
t Add new route: This should add a new route in the RouteInfo array by reading flight number, source & destination. This new route also will be appended into the file Routes.txt
For example:
t SV555 Dammam Tabuk
f Add new Fleet: This should add a new entry in Flight array and will be appended into the file Flight.txt
For example:
f SV0285 Saudi Arabian Airlines; Wednesday
q Exithello guys can any expret help me to do my project
the dead line is sunday
please help [email protected]
well, I'll give you credit for a clever nick. But really - I'm working on almost the same thing here
http://www.answers.com/topic/global-air-transportation-execution-system
And I've got a deadline of July, but somehow I don't think the project manager would take it too well if I suggested that my plan should involve begging someone out on the java fora to do the project for me.
But come on - you have until Sunday! That's way longer than I had when I blew off my assignments in college, and I still managed to turn something in. Just pick up some caffeine and spend some time writing out things on paper and you'll get it, no worries. And if you run into specific coding troubles then post here and someone will likely help you out.
Good Luck
Lee -
Utilsing an array to fix a problem
I have created the below array and I wish to utilise the elements within
it. Basically I have to create a program that inputs a date say 12/06/65
and outputs 12 june 65.
The array is below
public class MonthList
private int nextFreeLocation;
public MonthList()
Month [] monthList = {new Month ("January ", 31),
new Month ("February ", 28),
new Month ("March ", 31),
new Month ("April ", 30),
new Month ("May ", 31),
new Month ("June ", 30),
new Month ("July ", 31),
new Month ("August ",31),
new Month ("September ",30),
new Month ("October ", 31),
new Month ("November ", 30),
new Month ("December ", 31)};
My array is based on a class I created month and is passed in a string for
the monthname and an int to set the days as constant to the month. I need
a method or a loop so that when someone enters data from the keyboard and
say presses 6 it will automatically recgonise it as June. Any ideas, i
have already created an inputDate.class and will code my own Date
Exceptions when I have found a way of initialising the user input with the
month and the days set for that month.
Please helpA vector is a great expanding array utility, you can always add and remove from it, with an Object array you need to set it up with a certain size and that is all you get. You can use the Vector to add Objects to it (days of the week) and specify an index associated with that object, then when you need the object back you can call the Vector's get method with an index alone.
The benefit for your application would be a lot of saved coding, you see if Monday is 1, Tuesday is 2 and so on and you put them in the array with that index, then you know when a user enters 3 that they have chosen Wendesday and you can call Vector.get( 3 ) and you will automatically get Wednesdays Object. Did I explain that good? -
Does anyone use f4l on Arch? Im trying to install it, but I cannot succeed in the last step. Im following the steps described in Flash For Linux website:
qmake -project
qmake -o Makefile f4l.pro
make
And everything seems to be working, but I do not get the "f4l" file, which lunches the program. Am I missing something here?You can use any animation program, then convert to flv/swf. Maybe something like Synfig will help (vector animation), but currently it is broken in AUR.
Hey wait, it appears that none of us replied to your main issue and derailed
First of all, any kind of make only "builds" files. Normally, for installation, there would be "make install" which is a set of commands to place files into places defined by you (with something like make PREFIX=/somewhere install or DESTDIR=/somewhere) or it uses default paths. If not, you have to locate the needed files yourself and place them yourselves/use them from within the directory. Locate a /bin folder and that's where the executable(s) would be. -
HELP!!Need to import and print vector drawings
I am trying this topic again in the hope of help. I need to
import drawings in a vector format for printing. These drawings
will be cast members not sprites. I have tried printing a swf
version via Printomatic but it cannot print Flash members. My
questions are:
1. Is therre any way to print a swf cast member (not a
sprite)
2. How can I import an EPS file? - I have heard that it can
be done but every version I have tried seems to failDarrel Plant has written an importer for .ai and .eps files.
You can get
it at:
http://www.moshplant.com/direct-or/ps2vs/
Haven't used it for a while but it works pretty good.
Downside is that it creates multiple members because Director
can't
(couldn't?) handle multiple-line vector members.
Dsotm wrote:
> I am trying this topic again in the hope of help. I need
to import drawings in
> a vector format for printing. These drawings will be
cast members not sprites.
> I have tried printing a swf version via Printomatic but
it cannot print Flash
> members. My questions are:
> 1. Is therre any way to print a swf cast member (not a
sprite)
> 2. How can I import an EPS file? - I have heard that it
can be done but every
> version I have tried seems to fail
>
Manno Bult
[email protected] -
Please help with retrieving values from object stored in a vector
hi..
i have a class Magazine with 2 varibles name and price like this
class magazine
String name;
int price;
i have created a vector called selectedmag which stores objects of Magazine class... now each object will contain the name and price rite...
i want to print the values stored in vector ie i want to print the vector elements...like
Name: Mag1
Price: 10
which wil be present in object1...
and then
Name: Mag2
Price:15
which wil be present in object2...
and so on...
plz help...
if i give selectedmag.elementAt(position) i am not able to get the above output...plz help me.....
thanks,
Akshathahi,
Yes i have used a for loop to print the values... it goes like this
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
class Magazine
String title;
int price;
public class sessiontrack1 extends HttpServlet
public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
res.setContentType("text/html");
PrintWriter out=res.getWriter();
HttpSession session=req.getSession(true);
// This is my vector
Vector myshoppingcart=(Vector)session.getAttribute("ShoppingCart");
if(myshoppingcart==null)
myshoppingcart=new Vector();
Magazine selectedMag=new Magazine();
selectedMag.title=req.getParameter("Title");
selectedMag.price=Integer.parseInt(req.getParameter("Price"));
//Putting Magazine object into the vector myshoppingcart
myshoppingcart.addElement(selectedMag);
session.setAttribute("ShoppingCart",myshoppingcart);
out.println("<html><body>U have selected these magazines");
out.println("<br>");
//Enumeration vEnum=myshoppincart.elements();
//here a am trying to print output the values
for(int i=0;i<myshoppingcart.size();i++)
out.println("Name:" + (Magazine)myshoppingcart.elementAt(i));
out.println("<br>");
out.println("Price:" + (Magazine)myshoppingcart.elementAt(i));
out.println("<br>");
out.println("</body></html>");
this is a servlet program.... plz suggest me how to print the values... in the following format
Name: Book1
price: Rs 10
Name:Book2
price:Rs 15
Akshatha -
How do I print out the attributes of objects from a Vector? Help !
Dear Java People,
I have created a video store with a video class.I created a vector to hold the videos and put 3 objects in the vector.
How do I print out the attributes of each object in the vector ?
Below is the driver and Video class
Thank you in advance
Norman
import java.util.*;
public class TryVideo
public static void main(String[] args)
Vector videoVector = new Vector();
Video storeVideo1 = new Video(1,"Soap Opera", 20);
Video storeVideo2 = new Video(2,"Action Packed Movie",25);
Video storeVideo3 = new Video(3,"Good Drama", 10);
videoVector.add(storeVideo1);
videoVector.add(storeVideo2);
videoVector.add(storeVideo3);
Iterator i = videoVector.interator();
while(i.hasNext())
System.out.println(getVideoName() + getVideoID() + getVideoQuantity());
import java.util.*;
public class Video
public final static int RENT_PRICE = 3;
public final static int PURCHASE_PRICE = 20;
private int videoID;
private String videoName;
private int videoQuantity;
public Video(int videoID, String videoName, int videoQuantity)
this.videoID = videoID;
this.videoName = videoName;
this.videoQuantity = videoQuantity;
public int getVideoID()
return videoID;
public String getVideoName()
return videoName;
public int getVideoQuantity()
return videoQuantity;
}Dear Bri81,
Thank you for your reply.
I tried the coding as you suggested
while(i.hasNext())
System.out.println( i.next() );
but the error message reads:
"CD.java": Error #: 354 : incompatible types; found: void, required: java.lang.String at line 35
Your help is appreciated
Norman
import java.util.*;
public class TryCD
public static void main(String[] args)
Vector cdVector = new Vector();
CD cd_1 = new CD("Heavy Rapper", "Joe", true);
CD cd_2 = new CD("Country Music", "Sam", true);
CD cd_3 = new CD("Punk Music", "Mary", true);
cdVector.add(cd_1);
cdVector.add(cd_2);
cdVector.add(cd_3);
Iterator i = cdVector.iterator();
while(i.hasNext())
System.out.println( i.next() );
public class CD
private String item;
private boolean borrowed = false;
private String borrower = "";
private int totalNumberOfItems;
private int totalNumberOfItemsBorrowed;
public CD(String item,String borrower, boolean borrowed)
this.item = item;
this.borrower = borrower;
this.borrowed = borrowed;
public String getItem()
return item;
public String getBorrower()
return borrower;
public boolean getBorrowed()
return borrowed;
public String toString()
return System.out.println( getItem() + getBorrower()); -
Need to sort two vectors at the same time! please help!
I have
vectorA: 2 4 9 1 7 6 8
vectorB: two four nine one seven six eight
i want to sort these two vectors in parallel
what is the best way?
i could just do Collection.sort(vectorA) and get
1 2 4 6 7 8 9
but i want the vectorB to have a corresponding order
please help!!
thankspublic class Pair implements Comparable {
private int value;
private String name;
public int getValue() {
return this.value;
public void setValue(int value) {
this.value = value;
public String getName() {
return this.name;
public void setName(String name) {
this.name = name;
public int compareTo(Object o) {
Pair that = (Pair) o;
return this.value - that.value;
place both in a Collection (vector is a bad choice if you are going to do sorting LinkedList is better) the Collections.sort method will sort
according to the compareTo method. -
Need help in storing data from JList into a vector
need help in doing the following.-
alright i click a skill on industryskills Jlist and press the add button and it'll be added to the applicantskills Jlist. how do i further store this data that i added onto the applicantskills JList into a vector.
here are the codes:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.text.*;
import java.util.*;
import java.util.Vector;
import javax.swing.JScrollPane.*;
//import javax.swing.event.ListSelectionListener;
public class Employment extends JFrame
//declare class variables
private JPanel jpApplicant, jpEverything,jpWEST, jpCENTRE, jpEAST, jpAddEditDelete,
jpCentreTOP, jpCentreBOT, jpEastTOP, jpEastCENTRE, jpEastBOT,
jpBlank1, panel1, panel2, panel3, panel4,jpBottomArea,
jpEmptyPanelForDisplayPurposes;
private JLabel jlblApplicantForm, jlblAppList, jlblName, jlblPhone,
jlblCurrentSalary, jlblPassword, jlblDesiredSalary,
jlblNotes, jlblApplicantSkills, jlblIndustrySkills,
jlblBlank1, jlblBlank2, ApplicantListLabel,
NotesListLabel, ApplicantSkillsLabel,
IndustrySkillsLabel,jlblEmptyLabelForDisplayPurposes;
private JButton jbtnAdd1, jbtnEdit, jbtnDelete, jbtnSave, jbtnCancel,
jbtnAdd2, jbtnRemove;
private JTextField jtfName, jtfPhone, jtfCurrentSalary, jtfPassword,
jtfDesiredSalary;
private JTabbedPane tabbedPane;
private DefaultListModel /*listModel,*/listModel2;
String name,password,phone,currentsalary,desiredsalary,textareastuff,NotesText;
String selectedname;
final JTextArea Noteslist= new JTextArea();;
DefaultListModel listModel = new DefaultListModel();
JList ApplicantSkillsList = new JList(listModel);
private ListSelectionModel listSelectionModel;
JList ApplicantList, /*ApplicantSkillsList,*/ IndustrySkillsList;
//protected JTextArea NotesList;
//Vector details = new Vector();
Vector<StoringData> details = new Vector<StoringData>();
public static void main(String []args)
Employment f = new Employment();
f.setVisible(true);
f.setDefaultCloseOperation(EXIT_ON_CLOSE);
f.setResizable(false);
}//end of main
public Employment()
setSize(800,470);
setTitle("E-commerce Placement Agency");
Font listfonts = new Font("TimesRoman", Font.BOLD, 12);
JPanel topPanel = new JPanel();
topPanel.setLayout( new BorderLayout() );
getContentPane().add( topPanel );
createPage1();
createPage2();
createPage3();
createPage4();
tabbedPane = new JTabbedPane();
tabbedPane.addTab( "Applicant", panel1 );
tabbedPane.addTab( "Job Order", panel2 );
tabbedPane.addTab( "Skill", panel3 );
tabbedPane.addTab( "Company", panel4 );
topPanel.add( tabbedPane, BorderLayout.CENTER );
public void createPage1()//PAGE 1
/*******************TOP PART********************/
panel1 = new JPanel();
panel1.setLayout( new BorderLayout());
jpBottomArea = new JPanel();
jpBottomArea.setLayout(new BorderLayout());
jpApplicant= new JPanel();
jpApplicant.setLayout(new BorderLayout());
Font bigFont = new Font("TimesRoman", Font.BOLD,24);
jpApplicant.setBackground(Color.lightGray);
jlblApplicantForm = new JLabel("\t\t\t\tAPPLICANT FORM ");
jlblApplicantForm.setFont(bigFont);
jpApplicant.add(jlblApplicantForm,BorderLayout.EAST);
panel1.add(jpApplicant,BorderLayout.NORTH);
panel1.add(jpBottomArea,BorderLayout.CENTER);
/********************************EMPTY PANEL FOR DISPLAY PURPOSES*************************/
jpEmptyPanelForDisplayPurposes = new JPanel();
jlblEmptyLabelForDisplayPurposes = new JLabel(" ");
jpEmptyPanelForDisplayPurposes.add(jlblEmptyLabelForDisplayPurposes);
jpBottomArea.add(jpEmptyPanelForDisplayPurposes,BorderLayout.NORTH);
/*****************************************WEST*********************************/
jpWEST = new JPanel();
jpWEST.setLayout( new BorderLayout());
//Applicant List
listModel2=new DefaultListModel();
ApplicantList = new JList(listModel2);
listSelectionModel = ApplicantList.getSelectionModel();
listSelectionModel.addListSelectionListener(new SharedListSelectionHandler());
JScrollPane scrollPane3 = new JScrollPane(ApplicantList);
ApplicantList.setPreferredSize(new Dimension(20,40));
scrollPane3.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPane3.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
ApplicantListLabel = new JLabel( "Applicant List:");
jpWEST.add(ApplicantListLabel,"North");
jpWEST.add(scrollPane3,"Center");
jpBottomArea.add(jpWEST,BorderLayout.WEST);
/*********CENTRE*********/
jpCENTRE = new JPanel();
jpCENTRE.setLayout(new GridLayout(2,1));
jpCentreTOP = new JPanel();
jpBottomArea.add(jpCENTRE,BorderLayout.CENTER);
jpCENTRE.add(jpCentreTOP);
jpCentreTOP.setLayout(new GridLayout(6,2));
//Creating labels and textfields
jlblName = new JLabel( "Name:");
jlblBlank1 = new JLabel ("");
jtfName = new JTextField(18);
jlblBlank2 = new JLabel("");
jlblPhone = new JLabel("Phone:");
jlblCurrentSalary = new JLabel("Current Salary:");
jtfPhone = new JTextField(13);
jtfCurrentSalary = new JTextField(7);
jlblPassword = new JLabel("Password:");
jlblDesiredSalary = new JLabel("Desired Salary:");
jtfPassword = new JTextField(13);
jtfDesiredSalary = new JTextField(6);
//Add labels and textfields to panel
jpCentreTOP.add(jlblName);
jpCentreTOP.add(jlblBlank1);
jpCentreTOP.add(jtfName);
jpCentreTOP.add(jlblBlank2);
jpCentreTOP.add(jlblPhone);
jpCentreTOP.add(jlblCurrentSalary);
jpCentreTOP.add(jtfPhone);
jpCentreTOP.add(jtfCurrentSalary);
jpCentreTOP.add(jlblPassword);
jpCentreTOP.add(jlblDesiredSalary);
jpCentreTOP.add(jtfPassword);
jpCentreTOP.add(jtfDesiredSalary);
//Noteslist
jpCentreBOT = new JPanel();
jpCentreBOT.setLayout( new BorderLayout());
jpCENTRE.add(jpCentreBOT);
jpBlank1 = new JPanel();
// Noteslist = new JTextArea(/*Document doc*/);
JScrollPane scroll3=new JScrollPane(Noteslist);
scroll3.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
scroll3.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
NotesListLabel = new JLabel( "Notes:");
jpCentreBOT.add(NotesListLabel,"North");
jpCentreBOT.add(scroll3,"Center");
jpCentreBOT.add(jpBlank1,"South");
jpBottomArea.add(jpCENTRE,BorderLayout.CENTER);
/**********EAST**********/
//Applicant Skills Panel
//EAST ==> TOP
jpEAST = new JPanel();
jpEAST.setLayout( new BorderLayout());
jpEastTOP = new JPanel();
jpEastTOP.setLayout( new BorderLayout());
ApplicantSkillsLabel = new JLabel( "Applicant Skills");
JScrollPane scrollPane1 = new JScrollPane(ApplicantSkillsList);
scrollPane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
scrollPane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
ApplicantSkillsList.setVisibleRowCount(6);
jpEastTOP.add(ApplicantSkillsLabel,"North");
jpEastTOP.add(scrollPane1,"Center");
jpEAST.add(jpEastTOP,BorderLayout.NORTH);
jpBottomArea.add(jpEAST,BorderLayout.EAST);
//Add & Remove Buttons
//EAST ==> CENTRE
jpEastCENTRE = new JPanel();
jpEAST.add(jpEastCENTRE,BorderLayout.CENTER);
jbtnAdd2 = new JButton("Add");
jbtnRemove = new JButton("Remove");
//add buttons to panel
jpEastCENTRE.add(jbtnAdd2);
jpEastCENTRE.add(jbtnRemove);
//add listener to button
jbtnAdd2.addActionListener(new Add2Listener());
jbtnRemove.addActionListener(new RemoveListener());
//Industry Skills Panel
//EAST ==> BOTTOM
jpEastBOT = new JPanel();
jpEastBOT.setLayout( new BorderLayout());
String[] data = {"Access97", "Basic Programming",
"C++ Programming", "COBOL Programming",
"DB Design", "Fortran programming"};
IndustrySkillsList = new JList(data);
JScrollPane scrollPane = new JScrollPane(IndustrySkillsList);
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
IndustrySkillsLabel = new JLabel( "Industry Skills:");
jpEastBOT.add(IndustrySkillsLabel,"North");
jpEastBOT.add(scrollPane,"Center");
jpEAST.add(jpEastBOT,BorderLayout.SOUTH);
//BOTTOM
jpAddEditDelete= new JPanel();
jbtnAdd1= new JButton("Add");
jbtnEdit= new JButton("Edit");
jbtnDelete= new JButton("Delete");
jbtnSave= new JButton("Save");
jbtnCancel= new JButton("Cancel");
jpAddEditDelete.add(jbtnAdd1);
jpAddEditDelete.add(jbtnEdit);
jpAddEditDelete.add(jbtnDelete);
jpAddEditDelete.add(jbtnSave);
jpAddEditDelete.add(jbtnCancel);
jbtnEdit.addActionListener(new EditListener());
jbtnDelete.addActionListener(new DeleteListener());
jbtnEdit.addActionListener(new EditListener());
jbtnAdd1.addActionListener(new Add1Listener());
jbtnCancel.addActionListener(new CancelListener());
jpBottomArea.add(jpAddEditDelete,BorderLayout.SOUTH);
public void createPage2()//PAGE 2
panel2 = new JPanel();
panel2.setLayout( new GridLayout(1,1) );
panel2.add( new JLabel( "Sorry,under construction" ) );
public void createPage3()//PAGE 3
panel3 = new JPanel();
panel3.setLayout( new GridLayout( 1, 1 ) );
panel3.add( new JLabel( "Sorry,under construction" ) );
public void createPage4()//PAGE 4
panel4 = new JPanel();
panel4.setLayout( new GridLayout( 1, 1 ) );
panel4.add( new JLabel( "Sorry,under construction" ) );
public class Add1Listener implements ActionListener
public void actionPerformed(ActionEvent e)
name = jtfName.getText();
password = jtfPassword.getText();
phone = jtfPhone.getText();
currentsalary = jtfCurrentSalary.getText();
int i= Integer.parseInt(currentsalary);
desiredsalary = jtfDesiredSalary.getText();
int j= Integer.parseInt(desiredsalary);
StoringData person = new StoringData(name,password,phone,i,j);
// StoringData AppSkillsList = new StoringData(listModel);
details.add(person);
// details.add(AppSkillsList);
listModel2.addElement(name);
jtfName.setText("");
jtfPassword.setText("");
jtfPhone.setText("");
jtfCurrentSalary.setText("");
jtfDesiredSalary.setText("");
// NotesList.setText("");
public class Add2Listener implements ActionListener
public void actionPerformed(ActionEvent e)
String temp1;
temp1 = (String)IndustrySkillsList.getSelectedValue();
listModel.addElement(temp1);
public class RemoveListener implements ActionListener
public void actionPerformed(ActionEvent e)
int index = ApplicantSkillsList.getSelectedIndex();
listModel.remove(index);
public class EditListener implements ActionListener
public void actionPerformed(ActionEvent e)
jtfName.setEditable(true);
jtfPassword.setEditable(true);
jtfPhone.setEditable(true);
jtfCurrentSalary.setEditable(true);
jtfDesiredSalary.setEditable(true);
Noteslist.setEditable(true);
jbtnAdd2.setEnabled(true);
jbtnRemove.setEnabled(true);
jbtnSave.setEnabled(true);
jbtnCancel.setEnabled(true);
public class DeleteListener implements ActionListener
public void actionPerformed(ActionEvent e)
int index1 = ApplicantList.getSelectedIndex();
listModel2.remove(index1);
public class SaveListener implements ActionListener
public void actionPerformed(ActionEvent e)
public class CancelListener implements ActionListener
public void actionPerformed(ActionEvent e)
jtfName.setText("");
jtfPassword.setText("");
jtfPhone.setText("");
jtfCurrentSalary.setText("");
jtfDesiredSalary.setText("");
public class SharedListSelectionHandler implements ListSelectionListener
public void valueChanged(ListSelectionEvent e)
selectedname =ApplicantList.getSelectedValue().toString();
StoringData selectedPerson = null;
jtfName.setEditable(false);
jtfPassword.setEditable(false);
jtfPhone.setEditable(false);
jtfCurrentSalary.setEditable(false);
jtfDesiredSalary.setEditable(false);
Noteslist.setEditable(false);
jbtnAdd2.setEnabled(false);
jbtnRemove.setEnabled(false);
jbtnSave.setEnabled(false);
jbtnCancel.setEnabled(false);
for (StoringData person : details)
if (person.getName1().equals(selectedname))
selectedPerson = person;
jtfName.setText(person.getName1());
jtfPassword.setText(person.getPassword1());
jtfPhone.setText(person.getPhone1());
//String sal1 = Integer.parseString(currentsalary);
// String sal2 = Integer.parseString(desiredsalary);
// jtfCurrentSalary.setText(sal1);
// jtfDesiredSalary.setText(sal2);
break;
// if (selectedPerson != null)
}Quit posting 300 line programs to ask a question. We don't care about your entire application. We only care about code that demonstrates your current problem. We don't want to read through 300 lines to try and find the line of code that is causing the problem.
If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program (SSCCE) that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
And don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags so the code retains its original formatting.
Here is a simple SSCCE. Now make your changes and if you still have problems you have something simple to post. If it works then you add it to your real application.
Learn to simplify your problem by simplifying the code.
import java.awt.*;
import javax.swing.*;
public class ListTest2 extends JFrame
JList list;
public ListTest2()
String[] numbers = { "one", "two", "three", "four", "five", "six", "seven" };
list = new JList( numbers );
JScrollPane scrollPane = new JScrollPane( list );
getContentPane().add( scrollPane );
public static void main(String[] args)
ListTest2 frame = new ListTest2();
frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
frame.setSize(200, 200);
frame.setLocationRelativeTo( null );
frame.setVisible( true );
}
Maybe you are looking for
-
I installed CC on my and my wife's home workstations months ago. Today, I installed Photoshop on my new laptop while at work and, not surprisingly, received a message at launch about my two-device limit having already been reached. The options pres
-
Tool Button Not Working in Adobe Reader 9
Hello, I have a custom tool button - folder level script (with a trusted function) to digitally sign a drawing template. The tool button works in Reader 8 and Reader X, but is not working in Reader 9. The error message is shown "Not Allowed Error: Se
-
Dreamweaver images not displaying
Hi, I have a site that is not displaying images. I have a blank box in the middle of the page that is supposed to display three images every few seconds. I have looked at the code and cannot see that issue. Here is the html fro the index.html I have
-
Installing Itunes on my computer after reinstalling windows.
hello, there is again a problem for me to install Itunes on my PC. I just re-installed Windows for certain reasons and the installation of Itunes doesnt work correctly. It is like that: i start the .exe file, it gets unpacked and the usual applicatio
-
Pinch to Zoom doesn't work properly!
Whether in Chrome or in Album, the pinch to zoom function doesn't perform as expected. It zooms irregularly and is also jerky by the way. In chrome, it's even worse. I am on .534 and also repaired using PCC, is this a software issue or should I be g