Java list help
I am trying to add some thing to my list , its getting added, when I try to add the second item first item is getting overridden, its a reference issue, even I create a new Instance and try to add, but still same issue, can some one please help me
here is the code I am using
private Programs theprogram= new Programs();
public void actionAddProgram(){
Programs abc= new Programs();
abc.setProgram(theprogram.getProgram());
programs.add(abc);
theprogram= new Programs();
}
here is the code
private int myAddressLineIndex = -1;
public int getAddressLineIndex() {
return myAddressLineIndex;
public void setAddressLineIndex(int theAddressLineIndex) {
myAddressLineIndex = theAddressLineIndex;
public void actionAddAddressLine() {
if (theprogram.getProgram() == null || theprogram.getProgram().length == 0) {
theprogram.setProgram(new String[]{programInstance});
}else {
List lines = new LinkedList(Arrays.asList(theprogram.getProgram()));
if (lines.contains(programInstance)) {
}else if (myAddressLineIndex > -1) {
lines.remove(myAddressLineIndex);
lines.add(myAddressLineIndex, programInstance);
}else {
lines.add(programInstance);
theprogram.setProgram((String[])lines.toArray(new String[lines.size()]));
programInstance = "";
myAddressLineIndex = -1;
<TR>
<TD><B>Add new Programs:</B></TD>
<TD><h:inputText id="text2"
value="#{pc_Organization.programInstance}"
styleClass="inputText" size="60" ></h:inputText></TD>
<TD>
<hx:commandExButton value="ADD" title="add another program"
action="#{pc_Organization.actionAddAddressLine}"></hx:commandExButton>
</TD>
</TR>
<TR>
<TD>
</TD>
<TD>
<hx:dataIterator value="#{pc_Organization.theprogram.program}" var="pro">
<h:outputText value="#{pro}"/>
</hx:dataIterator>
</TD>
</TR>
public class Programs {
private String[] program;
public String[] getProgram() {
return program;
public void setProgram(String[] program) {
this.program = program;
}I have all the code here, can some one help now???
Similar Messages
-
Import Java Classes - How manipulate Java List in Oracle Form
Good afternoon,
I call a Web Service from Oracle Application Server 10g Forms Services but the object returned by the method is a java list. I created a stub/skeleton with JDeveloper and the communication between WebService and Oracle form works fine. The problem is how to desencapsulate the list within ORA_JAVA. I imported java.util.List it does not solve my problem.
Method called: public List DecryptToken(Context context, String token) throws Exception
This list will have in List.get(0) -> Context object
List.get(1) -> String
List get(2) -> String
List get(3) -> Param []
Thanks for your help.
best regards,
TThi,
try java stored procedure loop ur java list and get data in "type table" of requried data type
and use it as u desired.
piyush -
Hi,
I have an assignment on linked lists, as a beginner I am really struggling with it for hours...
I have to write the following methods without importing any libraries.
"Write an iterative method delete() for LinkedStackOfStrings that takes an integer parameter k and deletes the kth element (assuming it exists).
Write a method find() that takes an instance of LinkedStackOfStrings and a string key as arguments and returns true if some node in the list has key as its item field, false otherwise."
It must be implemented in the code on this site:
[http://www.cs.princeton.edu/introcs/43stack/LinkedStackOfStrings.java.html]
Help would be appreciated! I have been trying for hours :(vdL wrote:
Thanks for the reply! Yes, I forgot add what my actual problem is.
If I am correct, I will need to be able to traverse through the list up to a certain point, redirect and redirect the pointers.
My problem is I am able to traverse through the list using 'for(Node x = first; x != null; x= x.next)' but I do not know how make it only run up to a particular position in the list.You can keep an integer counter, increment it each time through the loop, and break out of the loop when the counter is big enough. Example of breaking:
if (n == k) break;
And also, how not to loose the previous Node when traversing trough the list.You're allowed to have multiple references. So you could keep one reference to the current node, and one reference to the one before it.
Or, rather than looping through the list until you find the kth element, loop until you find the (k - 1)th element, then (if it exists) remove the one after it. -
I got to create an Array list this...
new Array('Requerimiento', '89', 'Esto es un requerimiento\nOtra l�nea', 'Producci�n', '90', 'Hola\nHola', 'Release', '91', '<BR>'));
exactly like this from a java List.. so i got to replace 'Requerimiento' for ((myObj)list.get(0)).getName(), replace '98' for ((myObj)list.get(0)).getId(). replace 'Esto es un requerimiento\nOtra l�nea' for ((myObj)list.get(0)).getDesc() and then the same cyclye but for position 1 in the list.
The array is dynamic so i can has as elements as the list has so i have no idea what to do and did this...
var taskTypes = new String();
List taskTypeList = timeKeeping.getValidTaskTypes(from, to);
for(int x = 0, i = 0; x < taskTypeList.size(); x += 3, i++) {
TaskType tt = (TaskType) taskTypeList.get(i);
%>
if(i + 1 == taskTypeList.size()) {
taskTypes.concat("<%= tt.getName() %>" + ',' + "<%= tt.getId() %>" + ',' + "<%= tt.getName() %>");
} else {
taskTypes.concat("<%= tt.getName() %>" + ',' + "<%= tt.getId() %>" + ',' + "<%= tt.getName() %>" + ',');
<%
%>but it doesn't work out...
help plz ! Thanks a lot.String.concat() does not add the string to the string, it returns a new string combining the 2, so you'd have to do this:
taskTypes = taskTypes.concat("<%= tt.getName() %>" + ',' + "<%= tt.getId() %>" + ',' + "<%= tt.getName() %>");
But, you need to be writing JavaScript... (I assume it's an array of arrays...)
var aArray = new Array();
<%
List taskTypeList = timeKeeping.getValidTaskTypes(from, to);
for(int x = 0, i = 0; x < taskTypeList.size(); x += 3, i++) {
TaskType tt = (TaskType) taskTypeList.get(i);
%>
aArray[aArray.length] = new Array('<%= tt.getName() %>', '<%= tt.getId() %>', '<%= tt.getName() %>' ... );
<% } %> -
Java Access Helper Jar file problem
I just downloaded Java Access Helper zip file, and unzipped, and run the following command in UNIX
% java -jar jaccesshelper.jar -install
I get the following error message, and the installation stopped.
Exception in thread "main" java.lang.NumberFormatException: Empty version string
at java.lang.Package.isCompatibleWith(Package.java:206)
at jaccesshelper.main.JAccessHelperApp.checkJavaVersion(JAccessHelperApp.java:1156)
at jaccesshelper.main.JAccessHelperApp.instanceMain(JAccessHelperApp.java:159)
at JAccessHelper.main(JAccessHelper.java:39)
If I try to run the jar file, I get the same error message.
Does anyone know how I can fix this?
ThanksCross-posted, to waste yours and my time...
http://forum.java.sun.com/thread.jsp?thread=552805&forum=54&message=2704318 -
I just downloaded Java Access Helper zip file, and unzipped, and run the following command in UNIX
% java -jar jaccesshelper.jar -install
I get the following error message, and the installation stopped.
Exception in thread "main" java.lang.NumberFormatException: Empty version string
at java.lang.Package.isCompatibleWith(Package.java:206)
at jaccesshelper.main.JAccessHelperApp.checkJavaVersion(JAccessHelperApp.java:1156)
at jaccesshelper.main.JAccessHelperApp.instanceMain(JAccessHelperApp.java:159)
at JAccessHelper.main(JAccessHelper.java:39)
If I try to run the jar file, I get the same error message.
Does anyone know how I can fix this?
Thankssorry ab the multiple post, it was urgent for me to
know the answer.
I've JDK 1.4.2 and JAccessHelper should work with 1.3
or later
Can there be some kind of path problems?No, I doubt it. It's just some internal app failure - looks like it's trying to determine the running Java version, and is not doing a good job at it. But the failure has nothing per se to Java, it's that specific app - what are we supposed to know about that app though? -
Hi how to find list help in parameters..?
hi gurus
i have some doubt..?
my selection-screen is
sales organization,
distributed channel,
division..
i got list help for sales organization
but i could not get list help for remaining two.
i need list help for distributed channel from that sales organization,
division list help for combination of sales organization n distributed channel,
finally i got the customer list of those combination on selection-screen itself.
can anybody suggest me
how to solve that.
thank you
regards
kals.Hi,
Use the below logic.
tables: t001k.
For Identification Number
DATA: BEGIN OF it_bwkey OCCURS 0,
bwkey LIKE t001k-bwkey,
END OF it_bwkey.
data: v_bukrs(4).
For Run date
DATA: BEGIN OF it_bukrs OCCURS 0,
bukrs LIKE t001k-bukrs,
END OF it_bukrs.
DATA it_ret LIKE ddshretval OCCURS 0 WITH HEADER LINE.
SELECTION-SCREEN: BEGIN OF BLOCK main WITH FRAME TITLE text-001.
SELECTION-SCREEN SKIP.
PARAMETERS: p_bukrs(4) TYPE c.
SELECT-OPTIONS s_bwkey FOR t001k-bwkey NO INTERVALS.
SELECTION-SCREEN END OF BLOCK main.
Validation Section
INITIALIZATION.
SELECT DISTINCT bukrs FROM t001k INTO TABLE it_bukrs.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_bukrs.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'BUKRS'
dynpprog = sy-repid
dynpnr = sy-dynnr
dynprofield = 'P_BUKRS'
value_org = 'S'
TABLES
value_tab = it_bukrs
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_bwkey-low.
TABLES: t130r.
DATA: BEGIN OF dynpfields OCCURS 0. "Hilfsstruktur zum auslesen des
INCLUDE STRUCTURE dynpread. "Feldwertes vom Dynpro bei >F4<
DATA: END OF dynpfields.
DATA : sy_repid LIKE sy-repid,
sy_dynnr LIKE sy-dynnr.
CLEAR dynpfields.
REFRESH dynpfields.
dynpfields-fieldname = 'P_BUKRS'.
APPEND dynpfields.
Lesen des akt. Wertes von Dynpro
sy_repid = sy-repid.
sy_dynnr = sy-dynnr.
CALL FUNCTION 'DYNP_VALUES_READ'
EXPORTING
dyname = sy_repid
dynumb = sy_dynnr
TABLES
dynpfields = dynpfields
EXCEPTIONS
OTHERS = 01.
IF sy-subrc = 0.
READ TABLE dynpfields WITH KEY fieldname = 'P_BUKRS'.
IF sy-subrc = 0.
v_bukrs = dynpfields-fieldvalue.
ENDIF.
ENDIF.
SELECT bwkey FROM t001k
INTO TABLE it_bwkey
WHERE bukrs = v_bukrs.
DELETE ADJACENT DUPLICATES FROM it_bwkey.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'BWKEY'
dynpprog = sy-repid
dynpnr = sy-dynnr
dynprofield = 'S_BWKEY'
value_org = 'S'
TABLES
value_tab = it_bwkey
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF. -
New to java(need help on access specifier)
hi! i am new to java.plzzzzz help me i have to make a project on access specifier's i know all theroy.but
i am unable to understand how i can define all specifiers practicly.i mean in a program.
thanks.plzzzzzzzz help methe most common project i can think of is a payroll system..
you can have real implementation of all the access specifiers
good luck -
Pascal to Java Please help me!
I am truobled in creating a validation method for the user loging in....
As I am perfect at Pascal can anyone translate the following pascla code to Java Please help me with this.
PROGRAM USERLOGIN;
TYPE
USER_TYPE = RECORD
USERNAME : STRING[15];
PASSWORD : STRING[15];
END;
USFILE = FILE OF USER_TYPE;
VAR
USER: USER_TYPE;
CKUSER: USER_TYPE;
RECFILE : USFILE;
I,J : INTEGER;
BEGIN
WRITE('ENTER USERNAME:');READLN(CKUSER.USERNAME);
WRITE('ENTER PASSWORD:');READLN(CKUSER.PASSWORD);
FILESPEC :='USERFILE.USR';
ASSIGN(RECFILE, FILESPEC);
RESET(RECFILE);
WHILE NOT EOF(RECFILE) DO
BEGIN
READ(RECFILE, USER);
IF CKUSER.USERNAME = USER.USERNAME AND CKUSER.PASSWORD = USER.PASSWORD THEN
LOGIN
ELSE
WRITE('USER NOT FOUND');
END;
END.Thank youDon't bother:
http://forum.java.sun.com/thread.jsp?forum=54&thread=539277 -
How I can enable Java ssv helper plugin silently for win7 users with IE9
here is what happens:
when I deploy java 7.21 on win7 users, after deployment when users try to Open their IE they get a login screen and apparently it is related to Java ssv helper plugin. it is trying to enable it and needs admin account/password. I am trying to deploy this to about 3000 computers and I dont want all of them start calling helpdesk for this.
your help is appreciated.The following article describes how to create a shared preference file. You can either create preferences that individual users can override, or create locked preferences that individual users cannot override.
http://kb.mozillazine.org/Lock_Prefs
(Note: I don't have any personal experience with these files, but another volunteer might post some additional tips and tricks.) -
Hey,
I am having trouble understanding the Linked List implementation code given under the Node Operations part of this pdf.
http://www.cs.berkeley.edu/~jrs/61b/lec/07.pdf
public ListNode(int item, ListNode next) {
this.item = item;
this.next = next;
public ListNode(int item) {
this(item, null);
ListNode l1 = new ListNode(7, new ListNode(0, new ListNode(6)));
I understand the earlier implementation, but this one has me confused. Would someone please go through/explain the flow of this implementation with me?
ThanksWell the code is pretty self explanitory.
a ListNode class that has two fields. an int field item, and a ListNode field next.
so when you create a ListNode object you can do so by one of two means passing one parameter or passing two parameters.
if you pass one parameter then you have a ListNode which has an int say 1 and a ListNode object who's value is null.
if you pass two parameters then you have a ListNode which has an int say 2 and a ListNode object who's value is the ListNode you pass to it.
ex ListNode myNode = ListNode(1,new ListNode(2));
so myNode now has an integer 1 and a reference to another ListNode which has an integer value of 2 and a reference to a null ListNode.
hope this helps. -
Why the same name of process comes out in AIX , in java. please help me.
Hello.
I have two questions related to Jvm.
I've developed Job scheduler program which is doing somthing as the DB schedule is set in the way of Multi
thread. Currently , I'm in the process of testing this one. It is good , if in the normal case. However, When
doing Shell, if the application have so a lot to do the Shell, it has a little problem.
My developing environment is
OS : AIX 5.3
JRE : IBM J9 VM (build 2.4, JRE 1.6.0 IBM J9 2.4 AIX ppc-32 jvmap3260sr7-20091214_49398
(JIT enabled, AOT enabled)
nofiles(descriptors) 2000
maxuproc 4096 Maximum number of PROCESSES allowed
per user True
In order to execute Shell in My Scheduler program , I tested Runtimeexec() or ProcessBuilder.
The result of mine in the test , when the executed Shell got over 300 is
1. The jvm processes that I execute at the first time are shown up , after Shell go to the finish, the
processes are all in the disappearance again , and at last The processes that I executed at the first time are
remaining. It's like the process is duplicated process in the maximum of 70.
When I do shell about 200 to be executed simultaneously, Duplicated jvm about 3 appeared momentarily, then
disappeared, and also under 120, No duplicated case is found when under 120.
ps -ef result is below , when shell is excuted
UID PID PPID C STIME TTY TIME CMD
jslee 626906 1 0 11, May - 2:20 java -
DD2_JC_HOME=/source/jslee/JOB -Dfile.encoding=euc-kr jobserver.JobServerMain
jslee 1421522 626906 0
19:36:16 - 0:00 java -DD2_JC_HOME=/source/jslee/JOB -Dfile.encoding=euc-kr jobserver.JobServerMain
....Skip.....
jslee 4374620 626906 0 19:34:06 - 0:00 java -DD2_JC_HOME=/source/jslee/JOB -
Dfile.encoding=euc-kr jobserver.JobServerMain
(the process list about 60)
*the first question : Why a lot of duplicated jvm are shown up when in alot of shell to be executed ?
*the second question : As you can see above , How can I solve out the problem.
*Is there some option that I can set up when starting Jvm?
---Next question---
My developing environment is
OS : SunOS 5.8
JRE : Java(TM) SE Runtime Environment (build 1.6.0_18-b07)
Java HotSpot(TM) Server
VM (build 16.0-b13, mixed mode)
nofiles(descriptors) 256
As shown obove , the value of descriptors is 256 .
My scheduler program executed 300 shell at the same time, in result my program was abnormalily
terminated after doing shell about 180.
the Exception info is
java.io.IOException: Cannot run program "sh": error=24, exceeding the number of opened files
at
java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at
java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
or
java.net.SocketException: exceeding the number of opened files at java.net.PlainSocketImpl.socketAccept
(Native Method)
또는
java.io.IOException: exceeding the number of opened files at
java.io.UnixFileSystem.createFileExclusively(Native Method)
at java.io.File.checkAndCreate(Unknown
Source)
at java.io.File.createTempFile(Unknown Source)
*question : If I continuously request to open a file that go over system limit, is it possible for JVM to be
terminated?
*question : Is there a method that obtains state of System limit in the java library.
*question : what is the best solution to cope with ?
Please help me
=struts-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
<form-beans>
<form-bean name="registrationForm" type="ndlinh.struts.lab.RegistrationForm" />
</form-beans>
<action-mappings>
<action path="/register"
type="ndlinh.struts.lab.RegistrationAction" // action class
name="registrationForm" // form bean name
validate="false"
scope="request"
input="registration.jsp" >
<forward name="success" path="/jsp/success.jsp" />
<forward name="failure" path="/jsp/failure.jsp" />
</action>
</action-mappings>
</struts-config>HTH -
I'm not able to do the DELETE and the SEARCH options on my list ( HELP!! )
import java.io.*;
public class StudentContactManager
public static void main(String[] args) throws IOException
char userSelection;
final int maxStudents = 10;
String [] Lname = new String [maxStudents];//LName= Last Name
String [] FName= new String [maxStudents];//FName=First Name
String [] En= new String [maxStudents];//En = Enrolment Number
String [] PhoneNo= new String [maxStudents];
int activeEntries = 0;
boolean found = false;
//================================
System.out.println ( "1 - Initialise contact detail list" );
System.out.println ( "2 - Display contact details list" );
System.out.println ( "3 - Insert new entry into cotact detail list" );
System.out.println ( "4 - Delete entry from contact detail list" );
System.out.println ( "5 - Search cotact detail list" );
System.out.println ( "Q - Quit" );
System.out.print ( "Option : " );
userSelection = Text.readChar ( "Enter option" );
while ( userSelection != 'Q' & userSelection != 'q' )
switch ( userSelection )
case '1': activeEntries=0 ;
break;
case '2': if (activeEntries > 0)//IF contact detail list contains entries
System.out.println("\tEnrolment Number\tFirst Name\tSecond Name\tTelephone Number");
for (int i = 0; i<activeEntries; i ++)//FOR each stored contact
{//DO
System.out.println();
System.out.println("\t"+En[i]+"\t"+"\t"+FName[i]+ Lname[i]+"\t"+"\t"+PhoneNo);//Display one/current contact detail
}//END-FOR
else
{// ELSE
System.out.println("Contact detail list empty");//Display �Contact detail list empty� message
}//END-IF
break;
case '3': if(activeEntries<maxStudents)
En[activeEntries]= Text.readString("Enter enrolment number");
found = false;
int i = 0;
while ( !found && i < activeEntries)
if (En[i].equals(En[activeEntries]) )
found = true;
else
i++;
}//end-if
}//end-while
if (found == false)
FName[activeEntries]=Text.readString("Enter first name");
Lname[activeEntries]=Text.readString("Enter last name");
PhoneNo[activeEntries]=Text.readString("Enter telephone number");
// Insert new contact details into contact detail list
activeEntries++;
else
System.out.println("Enrolment number already exists");
else
System.out.println("Contact detail list full");
break;
case '4': Text.showMessage("Selected Option 4");
break;
case '5':Text.showMessage("Selected option 5");
default: Text.showMessage("invalid selection, Please input a valid option");
break;
}//switch
userSelection = Text.readChar ( "Enter option" );
}//while
System.exit(0);
}//main
}//StudentContactManager
//===============================================================================
I need help with case 4 and case 5...the search option should include while statement. and the 5th case is the delete option
Thanks guys =).Please use the code tags when posting code (there is a button on the posting page for them). It would also help if you told us what you are trying to do, what error you are getting, and what you expect to get.
If you are just asking us to write the code for you, then you are in the wrong place. -
Java Calendar Help Needed :)
Hi,
I am trying to develop a Java Event Calendar which is able to display the calendar weekly. So the JPanel will be setup with 7 JLists for the days of the week. Buttons will allow switching of the days of the week, months and year.
Each JList corresponding to the day of the week will have its data obtained from the database using JDBC and loaded upon 're-drawing' of the lists.
However i am having trouble with the GUI side in understanding how to implement this, i am confident with the JList and database side of things, i have just used a similar example using the Calendar API for monthly displays, however i am unsure how to convert this to a weekly calendar.
Ideally 7 JLists will always be available in the panel in order M,T,W,T,F,S,S but some will be set to inactive (for example in the first and last weeks of the month).
If anyone has any suggestions please could you help me out :)
Sorry if what im trying to do is a bit confusing.
I've included the code i've been using for the monthly calendar
THANKS!!
public class CalendarPanel extends JPanel implements ActionListener {
private Calendar panelDate;
private Label monthLabel;
private Label yearLabel;
private Panel daysPanel;
private Vector calendarListeners;
private static final String days[] = {"S","M","T","W","T","F","S"};
public CalendarPanel(){
super(new BorderLayout());
panelDate = Calendar.getInstance();
buildUI();
public CalendarPanel(Calendar date){
super(new BorderLayout());
panelDate = (date != null) ? (Calendar)date.clone() : Calendar.getInstance();
buildUI();
public CalendarPanel(Date date){
super(new BorderLayout());
panelDate = Calendar.getInstance();
if(date != null) panelDate.setTime(date);
buildUI();
public Calendar getCalendar(){ return panelDate;}
public void setCalendar(Calendar date){
if(date != null){
panelDate = (Calendar)date.clone();
redrawPanel();
public void setCalendar(Date date){
if(date != null){
panelDate.setTime(date);
redrawPanel();
public int getYear(){ return panelDate.get(Calendar.YEAR);}
public String getMonthName(){
switch(panelDate.get(Calendar.MONTH)){
case Calendar.JANUARY: return "January";
case Calendar.FEBRUARY: return "February";
case Calendar.MARCH: return "March";
case Calendar.APRIL: return "April";
case Calendar.MAY: return "May";
case Calendar.JUNE: return "June";
case Calendar.JULY: return "July";
case Calendar.AUGUST: return "August";
case Calendar.SEPTEMBER: return "September";
case Calendar.OCTOBER: return "October";
case Calendar.NOVEMBER: return "November";
case Calendar.DECEMBER: return "December";
case Calendar.UNDECIMBER: return "Undecimber";
default: return "Unknown";
private void buildUI(){
this.add(buildHeaderPanel(), BorderLayout.NORTH);
daysPanel = new Panel(new GridBagLayout());
redrawPanel();
this.add(daysPanel, BorderLayout.CENTER);
// build the part of the gui that contains the month and year
// labels with their incrementors / decrementors
private Panel buildHeaderPanel(){
monthLabel = new Label(getMonthName(), Label.CENTER);
yearLabel = new Label(Integer.toString(panelDate.get(Calendar.YEAR)),
Label.CENTER);
GridBagConstraints gbc = new GridBagConstraints();
Panel headerPanel = new Panel(new GridBagLayout());
// month label and buttons
Panel panel = new Panel(new GridBagLayout());
Button button = new Button("-");
button.setActionCommand("decrease month");
button.addActionListener(this);
gbc.anchor = GridBagConstraints.EAST;
panel.add(button, gbc);
gbc.anchor = GridBagConstraints.CENTER;
panel.add(monthLabel, gbc);
button = new Button("+");
button.setActionCommand("increase month");
button.addActionListener(this);
gbc.anchor = GridBagConstraints.WEST;
panel.add(button, gbc);
gbc.anchor = GridBagConstraints.CENTER;
gbc.weightx = 1;
headerPanel.add(panel, gbc);
// year label and buttons
panel = new Panel(new GridBagLayout());
button = new Button("-");
button.setActionCommand("decrease year");
button.addActionListener(this);
gbc.anchor = GridBagConstraints.EAST;
gbc.weightx = 0;
panel.add(button, gbc);
gbc.anchor = GridBagConstraints.CENTER;
panel.add(yearLabel, gbc);
button = new Button("+");
button.setActionCommand("increase year");
button.addActionListener(this);
gbc.anchor = GridBagConstraints.WEST;
panel.add(button, gbc);
gbc.anchor = GridBagConstraints.CENTER;
gbc.weightx = 1;
headerPanel.add(panel, gbc);
return headerPanel;
// redraws the entire panel, including relaying out of
// the days buttons
private void redrawPanel(){
monthLabel.setText(getMonthName());
yearLabel.setText(Integer.toString(getYear()));
// redraw days panel
GridBagConstraints gbc = new GridBagConstraints();
// clear current days panel
daysPanel.removeAll();
gbc.fill = GridBagConstraints.BOTH;
gbc.gridx = 0;
gbc.gridy = 0;
gbc.weightx = 1;
gbc.weighty = 1;
// add days of week
for(int i = 0; i < days.length; i++, gbc.gridx++)
daysPanel.add(new Label(days, Label.CENTER), gbc);
gbc.gridx = 0;
gbc.gridy++;
// days of month
Button button; // day buttons
JTable day = new JTable();
Calendar today = Calendar.getInstance();
Calendar cellDay = (Calendar)today.clone();
int month = panelDate.get(Calendar.MONTH);
int year = panelDate.get(Calendar.YEAR);
// start with first of panels month
cellDay.set(year, month, 1);
gbc.gridx = cellDay.get(Calendar.DAY_OF_WEEK) - 1;
while( cellDay.get(Calendar.MONTH) == month ){
if(gbc.gridx > 6){
gbc.gridy++;
gbc.gridx = 0;
button = new Button(Integer.toString(cellDay.get(Calendar.DATE)));
button.addActionListener(this);
if( cellDay.equals(today)){
button.setForeground(Color.red);
daysPanel.add(button, gbc);
gbc.gridx++;
cellDay.add(Calendar.DAY_OF_MONTH, 1);
// re validate entire panel
validate();
// implementation of ActionListener interface
// currently no real need to create subclassed action
// events for calendar. All actions generated by this
// are action events (generated from the buttons).
// the action command will be one of the four below
// or a number (the label of the day button!).
public void actionPerformed(ActionEvent ae){
String command = ae.getActionCommand();
if(command.equals("increase month")){
panelDate.add(Calendar.MONTH, 1);
redrawPanel();
} else if(command.equals("decrease month")){
panelDate.add(Calendar.MONTH, -1);
redrawPanel();
} else if(command.equals("increase year")){
panelDate.add(Calendar.YEAR, 1);
redrawPanel();
} else if(command.equals("decrease year")){
panelDate.add(Calendar.YEAR, -1);
redrawPanel();
notifyCalendarListeners(ae);
// methods for keeping track of interested listeners
public void addCalendarActionListener(ActionListener al){
if(al != null){
if(calendarListeners == null) calendarListeners = new Vector();
calendarListeners.addElement(al);
public void removeCalendarActionListener(ActionListener al){
if((calendarListeners != null) && (al != null)){
calendarListeners.removeElement(al);
private void notifyCalendarListeners(ActionEvent ae){
if((calendarListeners != null) && (!calendarListeners.isEmpty())){
java.util.Enumeration e = calendarListeners.elements();
while(e.hasMoreElements())
((ActionListener)e.nextElement()).actionPerformed(ae);Hi,
Sorry for the change of screen name, i'm having trouble with my old account.
I have now got most of the system working. However I am having trouble working out how to stop the last days of the previous month appearing in the first week of the next month. For example on 'July 2008' , days 29 and 30 of June are present in the first week of July. How can i get rid of this? And also for the last week of the month, how to get rid of the first days of the next month?
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Vector;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import javax.swing.border.EtchedBorder;
* @category CalendarSystem
* @author Daniel Barrett
public class CalendarSystem extends JPanel implements ActionListener, MouseListener, KeyListener {
JPanel events = new JPanel();
JPanel action = new JPanel();
//Events Panel
DateComboBox eventDateChooser = new DateComboBox();
JTextField ref = new JTextField(10);
JTextArea eventDetails = new JTextArea();
JScrollPane scrollingArea = new JScrollPane(eventDetails);
JTextField dateF = new JTextField(15);
JTextField timeF = new JTextField(15);
String[] minutes = {"00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49","50","51","52","53","54","55","56","57","58","59"};
String[] hours = {"00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23"};
JComboBox minsComb = new JComboBox(minutes);
JComboBox hourComb = new JComboBox(hours);
//Actions Panel
JButton delete = new JButton("Delete");
JButton purge = new JButton("Purge");
JButton add = new JButton("Add");
JButton edit = new JButton("Edit");
JButton mview = new JButton("Month View");
protected JLabel monthLabel;
protected JLabel weekLabel;
protected JLabel lmonday = new JLabel("");
protected JLabel ltuesday = new JLabel("");
protected JLabel lwednesday = new JLabel("");
protected JLabel lthursday = new JLabel("");
protected JLabel lfriday = new JLabel("");
protected JLabel lsaturday = new JLabel("");
protected JLabel lsunday = new JLabel("");
protected Calendar calendar;
protected SimpleDateFormat monthFormat = new SimpleDateFormat("MMM yyyy");
protected SimpleDateFormat dayFormat = new SimpleDateFormat("MMM");
JPanel monthCont = new JPanel();
JPanel weekCont = new JPanel();
JPanel yearCont = new JPanel();
JPanel daysOfWeek = new JPanel();
JPanel monday = new JPanel();
JPanel tuesday = new JPanel();
JPanel wednesday = new JPanel();
JPanel thursday = new JPanel();
JPanel friday = new JPanel();
JPanel saturday = new JPanel();
JPanel sunday = new JPanel();
JList mondayEvents = new JList();
JScrollPane mondayEventsScroll = new JScrollPane(mondayEvents);
JList tuesdayEvents = new JList();
JScrollPane tuesdayEventsScroll = new JScrollPane(tuesdayEvents);
JList wednesdayEvents = new JList();
JScrollPane wednesdayEventsScroll = new JScrollPane(wednesdayEvents);
JList thursdayEvents = new JList();
JScrollPane thursdayEventsScroll = new JScrollPane(thursdayEvents);
JList fridayEvents = new JList();
JScrollPane fridayEventsScroll = new JScrollPane(fridayEvents);
JList saturdayEvents = new JList();
JScrollPane saturdayEventsScroll = new JScrollPane(saturdayEvents);
JList sundayEvents = new JList();
JScrollPane sundayEventsScroll = new JScrollPane(sundayEvents);
protected Color selectedBackground;
protected Color selectedForeground;
protected Color background;
protected Color foreground;
public CalendarSystem(){
setupDays();
setupHeaders();
setupEvents();
setupActions();
this.calendar = Calendar.getInstance();
this.calendar.setFirstDayOfWeek(Calendar.SUNDAY);
this.add(this.monthCont);
this.add(this.daysOfWeek);
this.add(this.weekCont);
this.add(this.events);
this.add(this.action);
this.setLayout(new BoxLayout(this,1));
this.setMaximumSize(new Dimension(400,30));
this.updateCalendar();
private void setupActions() {
this.action.setBorder(BorderFactory.createTitledBorder("Actions"));
this.action.add(this.add);
this.action.add(this.edit);
this.action.add(this.delete);
this.action.add(this.purge);
this.action.add(this.mview);
private void setupEvents() {
this.events.setBorder(BorderFactory.createTitledBorder("Event Details"));
this.events.setLayout(new BoxLayout(this.events,1));
JPanel row1 = new JPanel();
JPanel row2 = new JPanel();
JPanel row3 = new JPanel();
JLabel la = new JLabel("Reference");
JLabel da = new JLabel("Date");
JLabel time = new JLabel("Time");
JLabel det = new JLabel("Details");
this.ref.setEditable(false);
this.dateF.setEditable(false);
this.timeF.setEditable(false);
this.eventDetails.setEditable(false);
row1.add(la);
row1.add(this.ref);
row1.add(da);
row1.add(this.dateF);
row1.add(time);
row1.add(this.timeF);
row2.add(det);
scrollingArea.setPreferredSize(new Dimension(600,50));
row3.add(this.scrollingArea);
this.events.add(row1);
this.events.add(row2);
this.events.add(row3);
protected JLabel createUpdateButton(final int field, final int amount, final boolean month) {
final JLabel label = new JLabel();
final Border selectedBorder = new EtchedBorder();
final Border unselectedBorder = new EmptyBorder(selectedBorder.getBorderInsets(new JLabel()));
label.setBorder(unselectedBorder);
label.setForeground(foreground);
label.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent e) {
calendar.add(field, amount);
if(month){
updateMCalendar();}
else{
updateCalendar();
public void mouseEntered(MouseEvent e) {
label.setBorder(selectedBorder);
public void mouseExited(MouseEvent e) {
label.setBorder(unselectedBorder);
return label;
private void updateMCalendar() {
this.calendar.set(Calendar.DAY_OF_MONTH, 1);
updateCalendar();
private void setupHeaders() {
//MONTH CONTROLS
monthCont.setLayout(new BoxLayout(monthCont, BoxLayout.X_AXIS));
monthCont.setBackground(background);
monthCont.setOpaque(true);
JLabel label;
label = createUpdateButton(Calendar.YEAR, -1,false);
label.setText("<<");
label.setToolTipText("Previous Year");
monthCont.add(Box.createHorizontalStrut(12));
monthCont.add(label);
monthCont.add(Box.createHorizontalStrut(12));
label = createUpdateButton(Calendar.MONTH, -1,true);
label.setText("< ");
label.setToolTipText("Previous Month");
monthCont.add(label);
monthLabel =new JLabel("", JLabel.CENTER);
monthLabel.setForeground(foreground);
//monthCont.add(Box.createHorizontalGlue());
monthCont.add(Box.createHorizontalStrut(12));
monthCont.add(monthLabel);
monthCont.add(Box.createHorizontalStrut(12));
//monthCont.add(Box.createHorizontalGlue());
label =createUpdateButton(Calendar.MONTH, 1,true);
label.setText(" >");
label.setToolTipText("Next Month");
monthCont.add(label);
label = createUpdateButton(Calendar.YEAR, 1,false);
label.setText(">>");
label.setToolTipText("Next Year");
monthCont.add(Box.createHorizontalStrut(12));
monthCont.add(label);
monthCont.add(Box.createHorizontalStrut(12));
//WEEK CONTROLS
weekCont.setLayout(new BoxLayout(weekCont, BoxLayout.X_AXIS));
weekCont.setBackground(background);
weekCont.setOpaque(true);
JLabel label1;
label1 = createUpdateButton(Calendar.WEEK_OF_MONTH, -1,false);
label1.setText("<<");
label1.setToolTipText("Previous Week");
weekCont.add(label1);
weekLabel =new JLabel("", JLabel.CENTER);
weekLabel.setForeground(foreground);
JLabel lweek =new JLabel("Week: ", JLabel.CENTER);
lweek.setForeground(foreground);
//monthCont.add(Box.createHorizontalGlue());
weekCont.add(Box.createHorizontalStrut(12));
weekCont.add(lweek);
weekCont.add(weekLabel);
weekCont.add(Box.createHorizontalStrut(12));
//monthCont.add(Box.createHorizontalGlue());
label1 = createUpdateButton(Calendar.WEEK_OF_MONTH, 1,false);
label1.setText(">>");
label1.setToolTipText("Next Week");
weekCont.add(label1);
public void setupDays(){
monday.setLayout(new BoxLayout(monday,1));
tuesday.setLayout(new BoxLayout(tuesday,1));
wednesday.setLayout(new BoxLayout(wednesday,1));
thursday.setLayout(new BoxLayout(thursday,1));
friday.setLayout(new BoxLayout(friday,1));
saturday.setLayout(new BoxLayout(saturday,1));
sunday.setLayout(new BoxLayout(sunday,1));
monday.add(this.lmonday);
monday.add(this.mondayEventsScroll);
monday.setBorder(BorderFactory.createTitledBorder("Monday"));
tuesday.add(this.ltuesday);
tuesday.add(this.tuesdayEventsScroll);
tuesday.setBorder(BorderFactory.createTitledBorder("Tuesday"));
wednesday.add(this.lwednesday);
wednesday.add(this.wednesdayEventsScroll);
wednesday.setBorder(BorderFactory.createTitledBorder("Wednesday"));
thursday.add(this.lthursday);
thursday.add(this.thursdayEventsScroll);
thursday.setBorder(BorderFactory.createTitledBorder("Thursday"));
friday.add(this.lfriday);
friday.add(this.fridayEventsScroll);
friday.setBorder(BorderFactory.createTitledBorder("Friday"));
saturday.add(this.lsaturday);
saturday.add(this.saturdayEventsScroll);
saturday.setBorder(BorderFactory.createTitledBorder("Saturday"));
sunday.add(this.lsunday);
sunday.add(this.sundayEventsScroll);
sunday.setBorder(BorderFactory.createTitledBorder("Sunday"));
this.mondayEventsScroll.setPreferredSize(new Dimension(90,200));
this.monday.setPreferredSize(new Dimension(145,300));
this.tuesdayEventsScroll.setPreferredSize(new Dimension(90,200));
this.tuesday.setPreferredSize(new Dimension(145,300));
this.wednesdayEventsScroll.setPreferredSize(new Dimension(90,200));
this.wednesday.setPreferredSize(new Dimension(145,300));
this.thursdayEventsScroll.setPreferredSize(new Dimension(90,200));
this.thursday.setPreferredSize(new Dimension(145,300));
this.fridayEventsScroll.setPreferredSize(new Dimension(90,200));
this.friday.setPreferredSize(new Dimension(145,300));
this.saturdayEventsScroll.setPreferredSize(new Dimension(90,200));
this.saturday.setPreferredSize(new Dimension(145,300));
this.sundayEventsScroll.setPreferredSize(new Dimension(90,200));
this.sunday.setPreferredSize(new Dimension(145,300));
daysOfWeek.add(this.sunday);
daysOfWeek.add(this.monday);
daysOfWeek.add(this.tuesday);
daysOfWeek.add(this.wednesday);
daysOfWeek.add(this.thursday);
daysOfWeek.add(this.friday);
daysOfWeek.add(this.saturday);
private void updateCalendar() {
monthLabel.setText(monthFormat.format(calendar.getTime()) );
weekLabel.setText(String.valueOf(this.calendar.get(calendar.WEEK_OF_MONTH)));
//Blank out / empty strings for first elements that do not start on sunday
Calendar setupCalendar = (Calendar) calendar.clone();
setupCalendar.set(Calendar.DAY_OF_WEEK, setupCalendar.getFirstDayOfWeek());
// while(setupCalendar.get(Calendar.DAY_OF_WEEK) < calendar.getActualMaximum(Calendar.DAY_OF_WEEK)) {
//System.out.println("day of month: " + setupCalendar.get(Calendar.DAY_OF_MONTH));
//System.out.println("day of week: " + (setupCalendar.get(Calendar.DAY_OF_WEEK)));
//System.out.println("week of month: " + calendar.get(Calendar.WEEK_OF_MONTH) + "\n");
setDayLabels(setupCalendar.get(Calendar.DAY_OF_MONTH),setupCalendar.get(Calendar.DAY_OF_WEEK));
setupCalendar.set(Calendar.DAY_OF_WEEK, setupCalendar.get(Calendar.DAY_OF_WEEK) + 1);
setDayLabels(setupCalendar.get(Calendar.DAY_OF_MONTH),setupCalendar.get(Calendar.DAY_OF_WEEK));
setupCalendar.set(Calendar.DAY_OF_WEEK, setupCalendar.get(Calendar.DAY_OF_WEEK) + 1);
setDayLabels(setupCalendar.get(Calendar.DAY_OF_MONTH),setupCalendar.get(Calendar.DAY_OF_WEEK));
setupCalendar.set(Calendar.DAY_OF_WEEK, setupCalendar.get(Calendar.DAY_OF_WEEK) + 1);
setDayLabels(setupCalendar.get(Calendar.DAY_OF_MONTH),setupCalendar.get(Calendar.DAY_OF_WEEK));
setupCalendar.set(Calendar.DAY_OF_WEEK, setupCalendar.get(Calendar.DAY_OF_WEEK) + 1);
setDayLabels(setupCalendar.get(Calendar.DAY_OF_MONTH),setupCalendar.get(Calendar.DAY_OF_WEEK));
setupCalendar.set(Calendar.DAY_OF_WEEK, setupCalendar.get(Calendar.DAY_OF_WEEK) + 1);
setDayLabels(setupCalendar.get(Calendar.DAY_OF_MONTH),setupCalendar.get(Calendar.DAY_OF_WEEK));
setupCalendar.set(Calendar.DAY_OF_WEEK, setupCalendar.get(Calendar.DAY_OF_WEEK) + 1);
setDayLabels(setupCalendar.get(Calendar.DAY_OF_MONTH),setupCalendar.get(Calendar.DAY_OF_WEEK));
public void setDayLabels(int day, int dayOfWeek){
if(dayOfWeek == 1){
this.lsunday.setText(String.valueOf(day));
if(dayOfWeek == 2){
this.lmonday.setText(String.valueOf(day));
if(dayOfWeek == 3){
this.ltuesday.setText(String.valueOf(day));
if(dayOfWeek == 4){
this.lwednesday.setText(String.valueOf(day));
if(dayOfWeek == 5){
this.lthursday.setText(String.valueOf(day));
if(dayOfWeek == 6){
this.lfriday.setText(String.valueOf(day));
if(dayOfWeek == 7){
this.lsaturday.setText(String.valueOf(day));
@Override
public void actionPerformed(ActionEvent arg0) {
@Override
public void mouseClicked(MouseEvent arg0) {
// TODO Auto-generated method stub
@Override
public void mouseEntered(MouseEvent arg0) {
// TODO Auto-generated method stub
@Override
public void mouseExited(MouseEvent arg0) {
// TODO Auto-generated method stub
@Override
public void mousePressed(MouseEvent arg0) {
// TODO Auto-generated method stub
@Override
public void mouseReleased(MouseEvent arg0) {
// TODO Auto-generated method stub
@Override
public void keyPressed(KeyEvent arg0) {
// TODO Auto-generated method stub
@Override
public void keyReleased(KeyEvent arg0) {
// TODO Auto-generated method stub
@Override
public void keyTyped(KeyEvent arg0) {
// TODO Auto-generated method stub
public static void main(String args[]){
JFrame frame = new JFrame();
frame.setSize(1100, 670);
frame.add(new CalendarSystem());
frame.setVisible(true);
}Thanks
Dan -
Oracle ADF Data Control With Java List
Hello
I have a question regarding Data Controls that are based on Application Modules functions. In short I created function:
public List getListOfTest() {
List allTests = new ArrayList();
allTests.add("test1");
allTests.add("test2");
allTests.add("test3");
return allTests;
inside AppModuleImp.java
I tested this implementation through AppModule Oracle ADF Model Tester and it returns test1,test2,test3. So this is OK. Now I publisher function through Client Interfaces, and I can see it know in DataControl.
So I drag and drop function on my jsf page, and render it as a button. Also i drag and droped "return"(hierarchically beeneth/inside function getListOfTest in DataControll) from Data Control and rendered it as ADF table. I was hoping that this will show: test1,test2,test3 in ADF table.
But now when I run jsf page and it is displayed in browser I get:
Object java.util of type ApplicationModule is not found
What I am doing wroong. Please help. Thx
I use JDeveloper Studio Edition Version 11.1.2.2.0The solution is
public List<String> getListOfTest() {
List<String> allTests = new ArrayList<String>();
allTests.add("test1");
allTests.add("test2");
allTests.add("test3");
return allTests;
Problem was in generic List
Maybe you are looking for
-
I have to validate a numeric field in LC so that it is a 1, 2 or 3.
Is there a pattern I can use or do I have to create a custom script? If I use this: this.rawValue >= 0 && this.rawValue <= 3; if (this.rawValue < 1) {this.rawValue = 0;} if (this.rawValue > 3) {this.rawValue = 0;} I get a validation error for every
-
Is the Mail Me Button Spam-proof
Just wondering if the 'Mail Me' button in iLife '09 is safe from email harvesters? Or am I better with a contact form? I'm publishing to Mobile Me.
-
Strange Problem: Apps disappeared for no apparent reason
I updated my 3GS the first day the 4.0 update came out. I didn't have any problems. This Tuesday (the 6th) I woke up after my alarm went off on my phone and all of my apps were gone! I hadn't done anything weird to my phone... I didn't plug it into i
-
I have a 3gs, and it has been working mostly fine, excluding the poor battery life despite multiple restores, and what i think is a wearing away of my oleophobic coating. But the newest problem i have just encountered is a little magic trick that ins
-
Flex 4 HSlider Tick Marks?
How would one go about doing this. I have a class extending the Spark HSlider and a skin for it, but what kind of Display Object should I used to display the values for Tick Marks.. some code below: I figured DataGroup as a possible repeater componen