Do this code need to have BufferedInputStream?
Good day, Java Guru!
Here is my code:
BufferedInputStream inputStream = new BufferedInputStream(connection.getInputStream());
ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
byte[] result = new byte[128];
int totalBytes;
while((totalBytes = inputStream.read(result)) != -1) {
byteOutput.write(result, 0, totalBytes);
}Variable connection represents opened Socket connection which returns to us input stream with bytes.
Will it be effective to have BufferedInputStream while reading bytes if my approach also use byte[128] array to read them?
The default size for the buffer in BufferedInputStream is 4096. So, by using it in this code you will save 31 out of every 32 physical reads to the socket, i.e. 31/32 system calls, context switches, ... I believe you will find that it is beneficial. On the other hand if you were to use a bugger byte array, such as 4096 or more, you would find the BufferedInputStream to be a cost.
But as the other poster suggested you could have tested and measured this for yourself.
BTW it is rarely a good idea to read an entire socket stream into memory unless you know in advance that it's not very large. Consider what will happen if it's a multi-gigabyte movie. It's generally best to put it somewhere piece by piece, or parse it piece by piece as it comes in.
Similar Messages
-
What files does this code need?
I am trying to use this code from Java Examples In A Nutshell.
It is a short program that involves reading one and writing to another (I think!) The way I understand things is that there has to be two files for the program to be able to run, from_file & to_file . I have attempted to creat two txt files and saved them as these names in the same folder as the app. The code complies as you would expect, when I try to run it I get Usage: FileCopy <source> <destination> and the app never runs. I suspect I have not created the external files properly. If you can see where I have gone wrong let me know, layman's terms please, Dave.When running the compiled "FileCopy.class" with java command you must enter the names of files, i.e.;
java FileCopy "from_file" "to_file"
in the command line.
In this case args[0] is "from_file" and args[1] is "to_file." -
Is this code need to be enhanced further? If yes,please give your inputs
Hai Coders,
The code below is a part of a java file for authentication. Its working version. I want to know how can i write optimized code for authentication of username and password. Comment on my code how can I improve it.
Is it up to Standard ( up to good java programmer )
Is it possible to optimize my coder further?
Any other alternatives that works better than this code for authentication?
As a java Programmer rate my code(1 to 10)..
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:srcname","","");
Statement stmt=con.createStatement();
String str1="";//username & assume that getting input from user
String str2="";//password & assume that getting input from user
ResultSet rs=stmt.executeQuery("select * from tablename");
while(rs.next()) {
String s1=rs.getString(8);
String s2=rs.getString(1);
if((s1.equals(str1))&&(s2.equals(str2))) {
System.out.println("Success");
} catch(Exception e) {
System.out.println("Fail");
}Friends My new updated code,
Give comments to improve my code further,
package javaapplication1;
import java.sql.*;
* @author m.senthil kumar
public class Main {
public static void main(String[] yahoo) {
Connection con=null;
PreparedStatement pstmt=null;
ResultSet rs=null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:tecch", "uuu", "ppp");
String userName = "jav1a";//username & assume that getting input from user
String password = "java";//password & assume that getting input from user
pstmt = con.prepareStatement("select username from test where username=? and password=?");
pstmt.setString(1, userName);
pstmt.setString(2, password);
rs = pstmt.executeQuery();
boolean b = false;
while (rs.next()) {
b = true;
break;
if (b) {
System.out.print("Success");
} else {
throw new unauthorized();
} catch (Exception e) {
System.out.print(e);
} finally {
try{
if(rs!=null)
rs.close();
if (pstmt != null) {
pstmt.close();
if (con != null) {
con.close();
catch(Exception e)
System.out.print(e);
class unauthorized extends Exception {
public String toString() {
return "You are not authorized person";
} -
I NEED A FORM THAT LISTS NAMES IN ALPHBETIC ORDER ON THE LEFT SIDE GOING DOWN. THIS FORM ALSO NEEDS COLUMNS THAT HAVE PRODUCT IDENTIFICATION ON THE TOP OF THE COLUMNS.
Hi,
Is your question in the context of the responses that you collect (this is the View Responses tab) or the actual form that your end users will see?
In a nutshell, (1) a field in your form corresponds to a column in the responses table. (2) the caption text of the form field will be the column header (show up at the top of the column). (3) to list names in alphabetical in your form, you can use choices fields, like multiple choices field or drop down field - you will have to enter the name in alphabetical order manually.
Hope this helps,
Thanks,
Lucia -
What files does this code need part II?
This is a continuation of a question asked earlier today http://forum.java.sun.com/thread.jsp?forum=54&thread=321833 . I now have been able to run this app & it seems okay. But I am confused as I expected the to_file to be overwritten by the from_file.
However when I check text files they appear to be the same as they were at first. Why? Dave.Try again after deleting the "to_file" or use another name for the output file.
-
Where can I find the source code?
hello kringga, for some documentation about how to work with the source code please refer to mozilla's resources for developers: https://developer.mozilla.org/en-US/docs/Mozilla/Developer_guide/Source_Code
-
Can you help me with the WHERE clause? Any issue with this code block?
Hi,
I am looking for blogs or any document on how to implement a Lookup during data loads in BW.
The problem is that all those that I find on this site are mostly about u201CLookup in XIu201D
I have read bits and hints on different postings on this site and this is the best I could do for the scenario shown below:
I need to add the Chars: Char1, Char2, Char3 to CubeX
so that I can display the data for these 3 Chars in a report.
Char1 and Char2 are filled in ODS12 and Char3 is filled in Cube3.
Can you help me write a routine so that while loading data to CubeX, it will read Char1, Char2, Char3 from ODS12 and Cube3; and make them available in CubeX?
This is my attempt so far: continue:
u201C----
select /bic/Char1 from /bic/ODS12
select /bic/Char2 from /bic/ODS12
select /bic/Char3 from /bic/Cube3
into result
WHERE u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026
and objvers = 'A' .
end select.
u201C----
1. What should be my WHERE clause?
2. In the select statement, by studying samples on this where should there be an u201CMu201D in front of the ODS? e.g. select /bic/Char1 from /bic/MODS12
If so, what is the significance and the other options?
3. Should this code be in the Start routing of CubeX? Or any other possible location? Also, in the start routine does it matter where within the start routine this code needs to be placed?
4. Can you please fix this code and add any lines I may be missing?
Is what I am looking to do refer to as u201Cdoing a lookupu201D?
Thanksok
-
HI, I need your help. How can I delete all data, when I do not have the special security code, which I didn´t remember ? I also think, that I never create this code before. But I cannot put my settings back.
You must remember the code, if you can't then take the phone and proof of purchase to an Apple Store.
-
I have a licence code for Adobe CS6 Master Collection which I'm using for more than a year, suddeny I am in trial mode (all programs) an it seems that this code is not accepted anymore. Help needed!!
Chat Now button near the bottom for Activation and Deactivation problems may help
http://helpx.adobe.com/x-productkb/policy-pricing/activation-deactivation-products.html -
I received a text today while at work about iCloud keychain verification code. I have not signed up for it or anything that uses it. I work out of the city with limited internet access so not sure why I would be getting this. I only got this number about a month ago. Apparently someone else had the number before because I get texts from his family members wondering whats going on. I got one yesterday and the person didn't seem to thrilled that the number was cutoff and today I got 2 texts about iCloud Keychain which I don't even know what it is. Seems suspicious to me. If the person who use to own the number is doing it he should know it is not his number anymore because he obviously didn't pay his bills. I'm not too sure about iCloud Keychain so just want to know my info safe?? It says it can store credit card numbers which is what gets me worried. Frankly I think it's pretty stupid to save that kind if information with any kind of app. But I don't want some random person trying to access my personal information because they are bitter they lost their number. Please let me know as soon as possible so I can change passwords or anything that is needed.
thanksIf it were me, I would go to my carrier and get a new number. Since you have only had it for a month, the inconvenience would be minimal.
Barry -
Return Current month Data:Help needed in modifying this code of a Procedure
Hello Folks i have this scenario where i need to modify this code so that it has to return data from the Current month First Day to the previous Day if its a daily report and previous month data if its a monthly report.
I have no clue how to modify this code below. Currently the code is returning data for Monthly reports for the previous month. Does anyone have any idea how to modify so that the code meets the requirements of both daily and monthly reprts.
BEGIN
if v_lowdate is null or v_highdate is null then
select to_number(to_char(sysdate, 'DD')) into v_cur_day from dual;
if v_cur_day < 25 then
-- this is for the previous month run
Select Add_Months(trunc(sysdate, 'MONTH'), -1)
INTO V_LOWDATE
FROM DUAL;
SELECT Last_Day(ADD_Months(Sysdate, -1)) INTO V_Highdate From Dual;
else
-- this is for the current month run
Select trunc(sysdate, 'MONTH') INTO V_LOWDATE FROM DUAL;
SELECT Last_Day(Sysdate) INTO V_Highdate From Dual;
end if;
end if;
Thanks
Edited by: user11961230 on Sep 30, 2009 8:34 PMHi Frank, This is code till the "modifying Code" which we were working. I will post the code after the "modifying Code" in the next reply. Thanks
CREATE OR REPLACE PROCEDURE "POPULATE_RECOVERY_ACTIVITYHN"(p_lowdate date,
p_highdate date) IS
v_lowdate date := p_lowdate;
v_highdate date := p_highdate;
v_error_code NUMBER(20);
v_error_text VARCHAR2(300);
v_recovery_id Recovery.Recovery_ID%type;
v_loop_control Number(20);
v_settlement_id recovery.settlement_id%type;
V_Event_ID Event.Event_ID%Type;
V_Event_Case_ID Event_Case.Event_Case_ID%Type;
V_Recovery_Month Varchar2(100);
V_Major_Company Major_Client.Major_Client_Name%Type;
V_Company Client.Client_Name%Type;
V_Client_Policy_Identifier Varchar2(100);
V_Lan_ID Varchar2(10) := 'TROVERIS';
V_Recovery_Account Client.Account_Number%Type;
V_AccountA Number(2) := 0;
V_AccountB Number(2) := 0;
V_Unit Event_Client_Field.Client_Field_Data%Type;
V_Market Event_Client_Field.Client_Field_Data%Type;
V_case_open_date Event_case.Open_Date%type;
V_Employer_Group_Code Employer_Group.Employer_Group_Code%Type;
V_Unknown1 Number(2) := 0;
V_Fee_Schedule_Code Event_Case.Fee_Schedule_Code%Type;
V_Total_Fee_Percent Number(20, 2) := 0.00;
V_Subrogation_Fee_Percent Number(20, 2) := 0.00;
V_Unknown2 Number(2) := NULL;
V_Unknown3 Number(2) := NULL;
V_TOTAL_MEDICAL Number(20, 2) := 0.00;
V_Recovery_Amount Number(20, 2) := 0.00;
V_Total_Tax Number(20, 2) := 0.00;
V_Administrative_Tax Number(20, 2) := 0.00;
V_Total_NonCash_Fee Number(20, 2) := 0.00;
V_Total_NonCash_Positive Number(20, 2) := 0.00;
V_Total_NonCash_Negative Number(20, 2) := 0.00;
V_Total_Recovery Number(20, 2) := 0.00;
V_Total_NonCash_Fee_Positive Number(20, 2) := 0.00;
V_Total_NonCash_Fee_Negative Number(20, 2) := 0.00;
V_Total_Admin_Fee Number(20, 2) := 0.00;
V_Total_Fee Number(20, 2) := 0.00;
V_Total_NonCash_Tax_Positive Number(20, 2) := 0.00;
V_Total_NonCash_Tax_Negative Number(20, 2) := 0.00;
report_type Varchar2(2);
v_gl_num client.gl_num%type; -- *002*
v_net_billable client.net_billable%type; -- *003*
vevent_id event.event_id%type; -- *006*
v_prev_event event.event_id%type; -- *006*
v_prev_case event_case.event_case_id%type; -- *006*
v_tot_recovery recovery.amount%type; -- *006*
v_rec_amount recovery.amount%type; -- *006*
v_prev_rec_amt recovery.amount%type; -- *006*
v_prev_rec_month recovery_activity.recovery_month%type; -- *006*
v_tot_fee recovery_activity.total_fee%type; --*006*
v_mth_rev unbundled_recoveries.monthly_revenue%type; -- *006*
v_diff number(18, 2); -- *006*
v_nc_count number := 0; -- *006*
v_c_count number := 0; -- *006*
v_nc_tot recovery.amount%type; -- *006*
v_used_rev recovery_activity.total_fee%type; -- *006*
v_use_mth_rev unbundled_recoveries.monthly_revenue%type := 0; -- *006*
v_use_nc_mth_rev unbundled_recoveries.monthly_revenue%type := 0; -- *006*
v_prev_netbill client.net_billable%type; -- *006*
v_event_type event.event_type_code%type;
v_date_typed event.date_typed%type;
v_acc_client_id client.acc_client_id%Type;
v_Recovery_Revenue_GL_Num client.recovery_revenue_gl_num%Type;
v_Funds_Due_GL_num client.funds_due_gl_num%Type;
v_lob Varchar2(20);
v_nc_recovery_id recovery.recovery_id%Type;
/*Changed the Client_Policy_Identifier to concatenate the Retlation to insured code instead of the description
which was exceeding the column size in the table. SWL 09/03/02. Checked with the Design Doc.*/
CURSOR RECOVERY_INFO IS
SELECT Event.Event_ID,
Event_Case.Event_Case_ID,
TO_CHAR(Recovery.Recovery_Date, 'FMMONTHYYYY') As Recovery_Month,
Major_Client.Major_Client_Name AS Major_Company,
-- Client.Client_Name AS Company,
-- nvl(client.legacy_client_id,'DC')||'-'||substr(Client.Client_Name,1,55) AS Company, -- SWL 04/01/04 52653
substr(nvl(client.legacy_client_id,
decode(client.client_id, 1, 'DC', client.client_code)) || '-' ||
Client.Client_Name,
1,
60) AS Company,
Event.Client_Policy_Identifier ||
Event_Case.Relation_To_Insured_code as Client_Policy_Identifier,
Client.Account_Number as Recovery_Account,
Employer_Group.Employer_Group_Code,
Event_Case.Fee_Schedule_Code,
Recovery_ID,
Event_case.Open_Date,
'(' || recovery.recovery_transaction_internal || ')' ||
l.recovery_transaction_descripti, --fml 110276
recovery.settlement_id,
trim(client.gl_num), -- *002*
nvl(trim(client.net_billable), 'N'), -- *003*
recovery.amount, -- *006*,
event.event_type_code,
event.date_typed,
recovery_id,
Client.ACC_CLIENT_ID,
Recovery_Revenue_GL_Num,
Funds_Due_GL_num
FROM Recovery,
Settlement,
Event_Case,
Event,
Employer_Group,
Client,
Major_Client,
recovery_transaction_lookup l
Where to_date(Recovery.Recovery_Date, 'DD-MON-RR') between
TO_DATE(v_lowdate, 'DD-MON-RR') and
TO_DATE(v_highdate, 'DD-MON-RR')
AND Settlement.Settlement_id = Recovery.Settlement_id
AND Settlement.Event_Case_ID = Event_Case.Event_Case_id
AND Event_Case.Event_ID = Event.Event_ID
AND Event.Employer_Group_ID = Employer_Group.Employer_Group_ID(+)
AND Event.Client_ID = Client.Client_ID
AND Client.Major_Client_id = Major_Client.Major_Client_ID(+)
and recovery.settlement_id not in
(select settlement_id
from recovery
where to_date(Recovery.Recovery_Date, 'DD-MON-RR') between
TO_DATE(v_lowdate, 'DD-MON-RR') and
TO_DATE(v_highdate, 'DD-MON-RR')
AND recovery_transaction_internal in
('05', '50', '52', '51'))
--001
and client.invoice_flag = 'N' *005* commenting
-- SWL 05/03/05 #71231
and event.event_id in
(select event_id
from event_end_user eeu
where eeu.active_flag = 'Y'
and eeu.owner_flag = 'Y'
and eeu.end_user_id in
(select end_user_id
from end_user
where end_user.research_internal_user = 'Y'))
and recovery.recovery_transaction_internal =
l.recovery_transaction_internal --fml 110276
order by event.event_id, recovery.amount; -- *006*
-- SWL 05/03/05 #71231
-- end of 001
-- SWL 11/10/03 # 52743
-- *006*
CURSOR get_recovery(vevent_id event.event_id%type) IS
SELECT sum(r.amount)
FROM Recovery r
Where to_date(r.Recovery_Date, 'DD-MON-RR') between
TO_DATE(v_lowdate, 'DD-MON-RR') and
TO_DATE(v_highdate, 'DD-MON-RR')
and r.event_id = vevent_id
and r.settlement_id not in
(select settlement_id
from recovery
where to_date(Recovery.Recovery_Date, 'DD-MON-RR') between
TO_DATE(v_lowdate, 'DD-MON-RR') and
TO_DATE(v_highdate, 'DD-MON-RR')
AND recovery_transaction_internal in
('05', '50', '52', '51'))
and r.event_id in
(select event_id
from event_end_user eeu
where eeu.active_flag = 'Y'
and eeu.owner_flag = 'Y'
and eeu.end_user_id in
(select end_user_id
from end_user
where end_user.research_internal_user = 'Y'));
CURSOR RECOVERY_INFO_NC IS
SELECT distinct Event.Event_ID,
Event_Case.Event_Case_ID,
TO_CHAR(Recovery.Recovery_Date, 'FMMONTHYYYY') As Recovery_Month,
Major_Client.Major_Client_Name AS Major_Company,
-- Client.Client_Name AS Company,
-- nvl(client.legacy_client_id,'DC')||'-'||substr(Client.Client_Name,1,55) AS Company, /* SWL 04/01/04 52653 */
substr(nvl(client.legacy_client_id,
decode(client.client_id,
1,
'DC',
client.client_code)) || '-' ||
Client.Client_Name,
1,
60) AS Company,
Event.Client_Policy_Identifier ||
Event_Case.Relation_To_Insured_code as Client_Policy_Identifier,
Client.Account_Number as Recovery_Account,
Employer_Group.Employer_Group_Code,
Event_Case.Fee_Schedule_Code,
'(' || recovery.recovery_transaction_internal || ')' ||
l.recovery_transaction_descripti, --fml 110276
recovery.settlement_id,
trim(client.gl_num), -- *002*
nvl(trim(client.net_billable), 'N'), -- *003*
recovery.amount,-- *006*
recovery.recovery_id,
event.event_type_code,
event.date_typed,
Client.ACC_CLIENT_ID,
Recovery_Revenue_GL_Num,
Funds_Due_GL_num
FROM Recovery,
Settlement,
Event_Case,
Event,
Employer_Group,
Client,
Major_Client,
recovery_transaction_lookup l
Where to_date(Recovery.Recovery_Date, 'DD-MON-RR') between
TO_DATE(v_lowdate, 'DD-MON-RR') and
TO_DATE(v_highdate, 'DD-MON-RR')
AND Settlement.Settlement_id = Recovery.Settlement_id
AND Settlement.Event_Case_ID = Event_Case.Event_Case_id
AND Event_Case.Event_ID = Event.Event_ID
AND Event.Employer_Group_ID = Employer_Group.Employer_Group_ID(+)
AND Event.Client_ID = Client.Client_ID
AND Client.Major_Client_id = Major_Client.Major_Client_ID(+)
and recovery.settlement_id in
(select settlement_id
from recovery
where to_date(Recovery.Recovery_Date, 'DD-MON-RR') between
TO_DATE(v_lowdate, 'DD-MON-RR') and
TO_DATE(v_highdate, 'DD-MON-RR')
--001
AND recovery.recovery_transaction_internal in
('05', '50', '52', '51')
and client.invoice_flag = 'N' *005* commenting
/* SWL 05/03/05 #71231 */
and event.event_id in
(select event_id
from event_end_user eeu
where eeu.active_flag = 'Y'
and eeu.owner_flag = 'Y'
and eeu.end_user_id in
(select end_user_id
from end_user
where end_user.research_internal_user = 'Y'))
and recovery.recovery_transaction_internal =
l.recovery_transaction_internal --fml 110276
order by event.event_id, recovery.amount; -- *006*
/* SWL 05/03/05 #71231 */
--end of 001
-- *006*
CURSOR get_recovery_nc(vevent_id event.event_id%type) IS
SELECT sum(r.amount)
FROM Recovery r
Where to_date(r.Recovery_Date, 'DD-MON-RR') between
TO_DATE(v_lowdate, 'DD-MON-RR') and
TO_DATE(v_highdate, 'DD-MON-RR')
AND r.event_id = vevent_id
and r.settlement_id in
(select settlement_id
from recovery
where to_date(Recovery.Recovery_Date, 'DD-MON-RR') between
TO_DATE(v_lowdate, 'DD-MON-RR') and
TO_DATE(v_highdate, 'DD-MON-RR'))
AND recovery_transaction_internal in ('05', '50', '52', '51')
and r.event_id in
(select event_id
from event_end_user eeu
where eeu.active_flag = 'Y'
and eeu.owner_flag = 'Y'
and eeu.end_user_id in
(select end_user_id
from end_user
where end_user.research_internal_user = 'Y'));
CURSOR Recovery_Totals_Nc IS
Select Recovery_Detail.Recovery_Id, /* SWL 07/01/04 59016 */
max(NVL(Recovery_Detail.Fees_Percent, 0) +
NVL(Recovery_Detail.Admin_Percent, 0)) as Total_Fee_Percent,
max(NVL(Recovery_Detail.Fees_Percent, 0)) as Subrogation_Fee_Percent,
max(NVL(Recovery.Amount, 0)) as Recovery_Amount, /* SWL 04/01/04 52653 */
Sum(NVL(Recovery_detail.Fees, 0) + NVL(Recovery_Detail.Admin, 0)) as Total_Fee,
Sum(NVL(Recovery_Detail.Fees_Taxes, 0) +
NVL(Recovery_Detail.Admin_Taxes, 0)) as Total_Tax,
Sum(NVL(Recovery_Detail.Admin_Taxes, 0)) as Administrative_tax,
Sum(NVL(Recovery_Detail.Admin, 0)) as Total_Admin_Fee,
sum(recovery.retained_by_client) as Non_cash_fee, --fml 110276
sum(recovery.allocation_check_amount) as cash --fml 110276
From Settlement, Recovery, Recovery_Detail
Where Recovery.settlement_id = v_settlement_id
And recovery.recovery_id = v_recovery_id
And Settlement.Settlement_id = Recovery.Settlement_id
And Recovery.Recovery_id = Recovery_detail.Recovery_id(+)
and to_date(Recovery.Recovery_Date, 'DD-MON-RR') between
TO_DATE(v_lowdate, 'DD-MON-RR') and
TO_DATE(v_highdate, 'DD-MON-RR') /*SWL 12/03/04 */
-- Group by Recovery_Detail.Fees_Percent; /* SWL 04/01/04 52653 */
Group by Recovery_Detail.recovery_id;
v_cash_recovery recovery_activity.cash_recovery%type;
CURSOR Recovery_Totals_Positive_Nc IS
-- Select Sum(Recovery.Amount) as Total_NonCash_Positive, /* SWL 04/01/04 52653 */
Select max(Recovery.Amount) as Total_NonCash_Positive,
Sum(NVL(Recovery_Detail.Fees_Taxes, 0) +
NVL(Recovery_Detail.Admin_Taxes, 0)) as Total_NonCash_Tax_Positive
From Settlement, Recovery, Recovery_detail
Where Recovery.settlement_id = v_settlement_id
And Settlement.Settlement_id = Recovery.Settlement_id
and recovery.recovery_id = v_recovery_id /* SWL 07/01/04 59016 */
And Recovery.Amount >= 0
And Recovery.Recovery_id = Recovery_detail.Recovery_id(+)
And Recovery.Recovery_Transaction_Internal in
('05', '50', '52', '51')
-- Group by Recovery_Detail.Fees_Percent; /* SWL 04/01/04 52653 */
Group by Recovery_Detail.recovery_id;
CURSOR Recovery_Totals_Negative_Nc IS
-- Select Sum(Recovery.Amount) as Total_NonCash_Negative, /* SWL 04/01/04 52653 */
Select max(Recovery.Amount) as Total_NonCash_Negative,
Sum(NVL(Recovery_Detail.Fees_Taxes, 0) +
NVL(Recovery_Detail.Admin_Taxes, 0)) as Total_NonCash_Tax_Negative
From Settlement, Recovery, Recovery_Detail
Where Recovery.settlement_id = v_settlement_id
And Settlement.Settlement_id = Recovery.Settlement_id
and recovery.recovery_id = v_recovery_id /* SWL 07/01/04 59016 */
And Recovery.Amount < 0
And Recovery.Recovery_id = Recovery_detail.Recovery_id(+)
And Recovery.Recovery_Transaction_Internal in
('05', '50', '52', '51')
Group by Recovery_Detail.recovery_id;
-- Group by Recovery_Detail.Fees_Percent; /* SWL 04/01/04 52653 */
/* SWL 11/10/03 # 52743 */
CURSOR Event_Client_Unit IS
Select e.Client_Field_Data as Unit
From Event_Client_Field e, recovery r
Where r.Event_ID = e.Event_ID
AND r.Recovery_ID = V_Recovery_ID
AND e.Client_Field_Name = 'UNIT';
CURSOR Bill_totals IS
Select mv_billdetail_case_sum.sum_paid as TOTAL_MEDICAL
From mv_billdetail_case_sum
where mv_billdetail_case_sum.event_id = V_Event_ID;
CURSOR NonCash_Fee IS
Select NVL(Sum(Recovery.Amount), 0) as Total_NonCash_Fee
From Settlement, Recovery
Where Recovery.Recovery_ID = V_Recovery_ID
And Settlement.Settlement_id = Recovery.Settlement_id
And Recovery.
Recovery_Transaction_Internal in ('05', '50', '52', '51');
/* SWL 04/01/04 52653 */
CURSOR Recovery_Totals IS
Select round(avg(NVL(Recovery_Detail.Fees_Percent, 0) +
NVL(Recovery_Detail.Admin_Percent, 0)),
2) as Total_Fee_Percent,
round(avg(NVL(Recovery_Detail.Fees_Percent, 0)), 2) as Subrogation_Fee_Percent,
max(NVL(Recovery.Amount, 0)) as Recovery_Amount,
Sum(NVL(Recovery_detail.Fees, 0) + NVL(Recovery_Detail.Admin, 0)) as Total_Fee,
Sum(NVL(Recovery_Detail.Fees_Taxes, 0) +
NVL(Recovery_Detail.Admin_Taxes, 0)) as Total_Tax,
Sum(NVL(Recovery_Detail.Admin_Taxes, 0)) as Administrative_tax,
Sum(NVL(Recovery_Detail.Admin, 0)) as Total_Admin_Fee
From Settlement, Recovery, Recovery_Detail
Where Recovery.Recovery_ID = V_Recovery_ID
And Settlement.Settlement_id = Recovery.Settlement_id
And Recovery.Recovery_id = Recovery_detail.Recovery_id(+)
Group by Recovery_Detail.recovery_id;
CURSOR Recovery_Totals_Positive IS
/* Select Sum(Recovery.Amount) as Total_NonCash_Positive,
Sum(NVL(Recovery_Detail.Fees_Taxes,0)+ NVL(Recovery_Detail.Admin_Taxes,0)) as Total_NonCash_Tax_Positive
*/ /* SWL 04/01/04 52653 */
Select max(Recovery.Amount) as Total_NonCash_Positive,
Sum(NVL(Recovery_Detail.Fees_Taxes, 0) +
NVL(Recovery_Detail.Admin_Taxes, 0)) as Total_NonCash_Tax_Positive
From Settlement, Recovery, Recovery_detail
Where Recovery.Recovery_ID = V_Recovery_ID
And Settlement.Settlement_id = Recovery.Settlement_id
And Recovery.Amount >= 0
And Recovery.Recovery_id = Recovery_detail.Recovery_id(+)
And Recovery.Recovery_Transaction_Internal in ('04', '17', '15') /*SWL 10/05/04 #63919*/--*009* added 15
Group by Recovery_Detail.recovery_id;
-- Group by Recovery_Detail.Fees_Percent; /* SWL 04/01/04 52653 */
CURSOR Recovery_NonFEE_Positive IS
Select Sum(NVL(Recovery_Detail.Fees, 0) + NVL(Recovery_Detail.Admin, 0)) as Total_NonCash_Fee_Positive
From Settlement, Recovery, Recovery_detail
Where Recovery.Recovery_ID = V_Recovery_ID
And Settlement.Settlement_id = Recovery.Settlement_id
And Recovery.Amount >= 0
And Recovery.Recovery_id = Recovery_detail.Recovery_id(+)
And Recovery.Recovery_Transaction_Internal in
('05', '50', '52', '51')
Group by Recovery_Detail.recovery_id;
-- Group by Recovery_Detail.Fees_Percent; /* SWL 04/01/04 52653 */
CURSOR Recovery_Totals_Negative IS
/* Select Sum(Recovery.Amount) as Total_NonCash_Negative,*/ /* SWL 04/01/04 52653 */
Select max(Recovery.Amount) as Total_NonCash_Negative,
Sum(NVL(Recovery_Detail.Fees_Taxes, 0) +
NVL(Recovery_Detail.Admin_Taxes, 0)) as Total_NonCash_Tax_Negative
From Settlement, Recovery, Recovery_Detail
Where Recovery.Recovery_ID = V_Recovery_ID
And Settlement.Settlement_id = Recovery.Settlement_id
And Recovery.Amount < 0
And Recovery.Recovery_id = Recovery_detail.Recovery_id(+)
And Recovery.Recovery_Transaction_Internal in ('04', '17', '15') /*SWL 10/05/04 #63919*/--*009* added 15
Group by Recovery_Detail.recovery_id;
-- Group by Recovery_Detail.Fees_Percent; /* SWL 04/01/04 52653 */
CURSOR Recovery_NonFEE_Negative IS
Select Sum(NVL(Recovery_Detail.Fees, 0) + NVL(Recovery_Detail.Admin, 0)) as Total_NonCash_Fee_Negative
From Settlement, Recovery, Recovery_Detail
Where Recovery.Recovery_ID = V_Recovery_ID
And Settlement.Settlement_id = Recovery.Settlement_id
And Recovery.Amount < 0
And Recovery.Recovery_id = Recovery_detail.Recovery_id(+)
And Recovery.Recovery_Transaction_Internal in
('05', '50', '52', '51')
Group by Recovery_Detail.recovery_id;
-- Group by Recovery_Detail.Fees_Percent; /* SWL 04/01/04 52653 */
--This is a generic cursor which will be used to control the number of rows inserted into the recovery_activity table
--There has to be 1 row inserted into the recovery_activity table for each detail record in the recovery_detail table.
--However, if no recovery_detail record exists there will be only 1 insert into the recovery_activity table.
CURSOR Control_Detail_Loop
IS
Select 1
FROM Recovery,
Recovery_Detail
Where Recovery.Recovery_ID = Recovery_Detail.Recovery_ID(+)
And Recovery.Recovery_ID = V_Recovery_ID;
/* SWL 04/01/04 Commented since the only time there were more entries in rd for a recovery is when there is a split fees */
/* accounting does not want this to be displayed in detail. They need this aggregated as a single fee entry so the recovery */
/* activity table will now have a single entry corresponding to each recovery in the recovery table. (#52653) */
CURSOR Control_Detail_Loop IS
Select 1 FROM Recovery where Recovery.Recovery_ID = V_Recovery_ID;
/* DJ 10/25/04 # 64633 start*/
CURSOR Event_Client_Market IS
Select e.Client_Field_Data as Market
From Event_Client_Field e, recovery r
Where r.Event_ID = e.Event_ID
AND r.Recovery_ID = V_Recovery_ID
AND e.Client_Field_Name = 'MARKET';
/* DJ 10/25/04 # 64633 end*/
v_cur_day integer := 0;
-----dj
v_vendor_fee_wh number;
v_total_vendor_fee_wh number;
v_rec_itc recovery_activity.recovery_transaction_internal%type;
--v_settlement_id settlement.settlement_id%type;
--*004* start
function unbundled_fee(pevent_id event.event_id%type,
plowdate date,
phighdate date) return number is
-- function variables
v_fee number(18, 2) := 0;
v_month_revenue unbundled_recoveries.monthly_revenue%type := 0;
v_cum_revenue unbundled_recoveries.cum_revenue%type := 0;
v_contract_fee_per unbundled_recoveries.contractual_fee_per%type := 0;
v_prev_cum_revenue unbundled_recoveries.cum_revenue%type := 0;
v_cum_ub_rec unbundled_recoveries.cum_ub_recoveries%type := 0;
v_cum_inv_paid unbundled_recoveries.cum_inv_paid%type := 0;
v_month_rec unbundled_recoveries.monthly_recoveries%type := 0;
v_cum_rec unbundled_recoveries.cum_recoveries%type := 0;
v_event_id event.event_id%type;
begin
--v_month_rec and v_cum_inv_paid
begin
select event_id,
(select sum(r.amount)
from recovery r
where r.event_id = e.event_id
and trunc(r.recovery_date) between plowdate and phighdate) as monthly_recoveries,
-- *006* added cum_rec
(select nvl(sum(r.amount), 0)
from recovery r
where r.event_id = e.event_id
and trunc(r.recovery_date) <= trunc(phighdate)) as cum_recoveries,
(select sum(decode(nvl(ex.client_invoice_closed, 'N'),
'N',
ex.paid_amount,
ex.client_invoice_received))
from expense ex
where ex.event_id = e.event_id
and upper(ex.status) = 'PAID'
and trunc(ex.check_date) <= phighdate
and trim(ex.orig_client_invoice_date) is not null
and nvl(ex.client_invoice_dispute, 'Y') = 'N') as cum_invoiced_paid
into v_event_id, v_month_rec, v_cum_rec, v_cum_inv_paid
from event e
where e.event_id = pevent_id;
exception
when no_data_found then
v_event_id := 0;
v_month_rec := 0;
v_cum_rec := 0;
v_cum_inv_paid := 0;
when others then
v_event_id := 0;
v_month_rec := 0;
v_cum_rec := 0;
v_cum_inv_paid := 0;
end;
-- *007* start
-- if event previously written to table, get values from table
begin
select nvl(ub.cum_revenue, 0)
into v_prev_cum_revenue
from unbundled_recoveries ub
where ub.event_id = pevent_id
and ub.month_id =
(select max(a.month_id)
from unbundled_recoveries a
where a.event_id = pevent_id
and a.month_id < to_char(v_lowdate, 'YYYYMM'));
exception
when no_data_found then
v_prev_cum_revenue := 0;
when others then
v_prev_cum_revenue := 0;
end;
-- *007* end
--v_contract_fee_per
begin
select nvl(max(rd.fees_percent), 0)
into v_contract_fee_per
from recovery_detail rd
where rd.recovery_id in
(select r.recovery_id
from recovery r,
(select a.event_id, max(amount) as amount
from recovery a
where a.event_id = pevent_id
and trunc(a.recovery_date) between plowdate and
phighdate
group by a.event_id) max_r
where r.event_id = max_r.event_id
and trunc(r.recovery_date) between plowdate and phighdate
and r.amount = max_r.amount);
exception
when no_data_found then
v_contract_fee_per := 0;
when others then
v_contract_fee_per := 0;
end;
v_cum_ub_rec := nvl(v_cum_rec, 0) - nvl(v_cum_inv_paid, 0);
if ((nvl(v_cum_ub_rec, 0) > 0) and (nvl(v_month_rec, 0) <> 0)) then
-- latest cumulative unbundled recoveries > 0
v_cum_revenue := round(((v_contract_fee_per / 100) * v_cum_ub_rec),
2);
v_month_revenue := v_cum_revenue - v_prev_cum_revenue;
end if;
v_fee := v_month_revenue;
return v_fee;
exception
when others then
raise_application_error(-20106,
substr('populate_recovery_activity.undebundled_fee: ' ||
Sqlcode || Sqlerrm,
1,
500));
return v_fee;
end; -
Noob needs help with this code...
Hi,
I found this code in a nice tutorial and I wanna make slight
adjustments to the code.
Unfortunately my Action Script skills are very limited... ;)
This is the code for a 'sliding menue', depending on which
button u pressed it will 'slide' to the appropriate picture.
Here's the code:
var currentPosition:Number = large_pics.pic1._x;
var startFlag:Boolean = false;
menuSlide = function (input:MovieClip) {
if (startFlag == false) {
startFlag = true;
var finalDestination:Number = input._x;
var distanceMoved:Number = 0;
var distanceToMove:Number =
Math.abs(finalDestination-currentPosition);
var finalSpeed:Number = .2;
var currentSpeed:Number = 0;
var dir:Number = 1;
if (currentPosition<=finalDestination) {
dir = -1;
} else if (currentPosition>finalDestination) {
dir = 1;
this.onEnterFrame = function() {
currentSpeed =
Math.round((distanceToMove-distanceMoved+1)*finalSpeed);
distanceMoved += currentSpeed;
large_pics._x += dir*currentSpeed;
if (Math.abs(distanceMoved-distanceToMove)<=1) {
large_pics._x =
mask_pics._x-currentPosition+dir*distanceToMove;
currentPosition = input._x;
startFlag = false;
delete this.onEnterFrame;
b1.onRelease = function() {
menuSlide(large_pics.pic1);
b2.onRelease = function() {
menuSlide(large_pics.pic2);
b3.onRelease = function() {
menuSlide(large_pics.pic3);
b4.onRelease = function() {
menuSlide(large_pics.pic4);
I need to adjust five things in this code...
(1) I want this menue to slide vertically not horizontally.
I changed the 'x' values in the code to 'y' which I thought
would make it move vertically, but it doesn't work...
(2) Is it possible that, whatever the distance is, the
"sliding" time is always 2.2 sec ?
(3) I need to implement code that after the final position is
reached, the timeline jumps to a certain movieclip to a certain
label - depending on what button was pressed of course...
I tried to implement this code for button number two...
b2.onRelease = function() {
menuSlide(large_pics.pic2);
if (currentPosition = finalDestination) {
this.large_pics.pic2.gotoAndPlay("s1");
--> sliding still works but it doesn't jump to the
appropriate label...
(4) I wanna add 'Next' & 'Previous' buttons to the slide
show - what would be the code in this case scenario ?
My first thought was something like that Flash checks which
'pic' movieclip it is showing right now (pic1, pic2, pic3 etc.) and
depending on what button u pressed u go to the y value of movieclip
'picX + 1' (Next button) or 'picX - 1' (Previous button)...
Is that possible ?
(5) After implementing the Next & Previous buttons I need
to make sure that when it reached the last pic movieclip it will
not go further on the y value - because there is no more pic
movieclip.
Options are to either slide back to movieclip 'pic1' or
simply do nothing any more on the next button...
I know this is probably Kindergarten for you, but I have only
slight ideas how to do this and no code knowledge to back it up...
haha
Thanx a lot for your help in advance !
Always a pleasure to learn from u guys... ;)
MikeHi,
I made some progress with the code thanx to the help of
Simon, but there are still 2 things that need to be addressed...
(1) I want the sliding time always to be 2.2 sec...
here's my approach to it - just a theory but it might work:
we need a speed that changes dynamically depending on the
distance we have to travel...
I don't know if that applies for Action Scrip but I recall
from 6th grade, that...
speed = distance / time
--> we got the time (which is always 2.2 sec)
--> we got the disctance
(currentposition-finaldestination)
--> this should automatically change the speed to the
appropriate value
Unfortunately I have no clue how the action script would look
like (like I said my action script skills are very limited)...
(2) Also, one other thing I need that is not implemented yet,
is that when the final destination is reached it jumps to a certain
label inside a certain movieclip - every time different for each
button pressed - something like:
if (currentPosition = finalDestination) {
this.large_pics.pic2.gotoAndPlay("s1");
that statement just doesn't work when I put it right under
the function for each button...
Thanx again for taking the time !!!
Mike -
I am stuck with this code- I definitely need a bail out
I would appreciate if a good samaritan could add this code for me. I am at my wits end.
The program I am trying to write is supposed to add students with their personal information and then display them in a GUI.
I should be able to select a student and add a grade for that student.
Finally I should be able to get the average for all the grades added for this student and display the average grade.
My challenge is how to obtain all the added scores and show the students average .
I understand my best shot is to use VECTOR API.
I tried to write someething but it did not work at , obviously due to inexperience.
I just can't figure how to link this average display window to the Get Average button.
A student can have any number of grades.
I need someone to show me the way, may be little "code guide" I am waaaay lost
Thanks in advance
Little Delmarie.
THIS IS WHAT I HAVE DONE SO FAR . IT COMPILES nicely in DOS and Visual age
// CODE GradeSystem
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.*;
import java.awt.*;
* UsingJLists.java
* This is a sample program for the use of JLists. You can add a student by entering their
* information a clicking on add. You can remove a student by entering their information and
* clicking on remove. They must be in the list to be removed. You can modify a student by
* entering their information and clicking add. You will be asked for the new student
* information when using modify. The add and remove buttons will disappear when modifying
* is underway and the new information is being collected for updating.
* @author Delmarie
public class GradeSystem extends JDialog {
Vector studentGrades = new Vector();
JButton add, modify, remove;
JList theJList;
JPanel buttonPanel, textPanel, labelPanel, masterPanel, jlistPanel, infoPanel;
JTextField score, possibleScore, gradeType;
JLabel label1, label2, label3;
public class ModifyHandler implements ActionListener {
public void actionPerformed(java.awt.event.ActionEvent actionEvent) {
// get the student info from the text boxes
double dScore = 0;
double dPossibleScore = 0;
try {
String str1 = score.getText();
if (str1 != null) dScore = Double.parseDouble(str1);
String str2 = possibleScore.getText();
if (str2 != null) dPossibleScore = Double.parseDouble(str2);
catch(NumberFormatException e) {}
String sGradeType = gradeType.getText();
Grade grade = (Grade)theJList.getSelectedValue();
if (grade == null) {
score.setText("");
possibleScore.setText("");
gradeType.setText("");
return;
grade.setScore(dScore);
grade.setPossibleScore(dPossibleScore);
grade.setGradeType(sGradeType);
theJList.repaint();
public class RemoveHandler implements ActionListener {
public void actionPerformed(java.awt.event.ActionEvent actionEvent) {
int removeIndex = theJList.getSelectedIndex();
if (removeIndex == -1) {
score.setText("");
possibleScore.setText("");
gradeType.setText("");
return;
DefaultListModel model = (DefaultListModel) theJList.getModel();
model.removeElementAt(removeIndex);
studentGrades.removeElementAt(removeIndex);
// clear the textboxes
score.setText("");
possibleScore.setText("");
gradeType.setText("");
public class AddHandler implements ActionListener {
public void actionPerformed(ActionEvent actionEvent) {
// get the student info from the text boxes
double dScore = 0;
double dPossibleScore = 0;
try {
String str1 = score.getText();
if (str1 != null) dScore = Double.parseDouble(str1);
String str2 = possibleScore.getText();
if (str2 != null) dPossibleScore = Double.parseDouble(str2);
catch(NumberFormatException e) {}
String sGradeType = gradeType.getText();
// get the model and add the student to the model
Grade g = new Grade();
g.setScore(dScore);
g.setPossibleScore(dPossibleScore);
g.setGradeType(sGradeType);
studentGrades.add(g);
DefaultListModel model = (DefaultListModel) theJList.getModel();
model.addElement(g);
// display the added element
theJList.setSelectedValue(g, true);
public class WindowHandler extends WindowAdapter {
public void windowClosing(WindowEvent e) {
setVisible(false);
/** Creates a new instance of UsingJLists */
public GradeSystem(JFrame owner, boolean modal) {
super(owner, modal);
// create all of the components, put them in panels, and put the panels in JFrame
add = new JButton("Add");
modify = new JButton("Modify");
remove = new JButton("Remove");
score = new JTextField("");
score.setColumns(10);
possibleScore = new JTextField("");
gradeType = new JTextField("");
label1 = new JLabel("score");
label2 = new JLabel("possibleScore");
label3 = new JLabel("gradeType");
FlowLayout flow = new FlowLayout();
FlowLayout flow1 = new FlowLayout();
FlowLayout flow2 = new FlowLayout();
GridLayout grid1 = new GridLayout(7,1);
GridLayout grid2 = new GridLayout(7,1);
BorderLayout border3 = new BorderLayout();
buttonPanel = new JPanel(flow);
buttonPanel.add(add);
buttonPanel.add(modify);
buttonPanel.add(remove);
labelPanel = new JPanel(grid1);
//labelPanel.setBorder(BorderFactory.createLineBorder(Color.black));
labelPanel.add(Box.createVerticalStrut(20));
labelPanel.add(label1);
labelPanel.add(Box.createVerticalStrut(20));
labelPanel.add(label2);
labelPanel.add(Box.createVerticalStrut(20));
labelPanel.add(label3);
labelPanel.add(Box.createVerticalStrut(20));
textPanel = new JPanel(grid2);
//textPanel.setBorder(BorderFactory.createLineBorder(Color.black));
textPanel.add(Box.createVerticalStrut(20));
textPanel.add(score);
textPanel.add(Box.createVerticalStrut(20));
textPanel.add(possibleScore);
textPanel.add(Box.createVerticalStrut(20));
textPanel.add(gradeType);
textPanel.add(Box.createVerticalStrut(20));
infoPanel = new JPanel(new FlowLayout());
infoPanel.setBorder(BorderFactory.createTitledBorder("Grade Information"));
infoPanel.add(Box.createHorizontalStrut(10));
infoPanel.add(textPanel);
infoPanel.add(Box.createHorizontalStrut(10));
infoPanel.add(labelPanel);
infoPanel.add(Box.createHorizontalStrut(10));
theJList = new JList(new DefaultListModel());
theJList.addListSelectionListener(new javax.swing.event.ListSelectionListener(){
public void valueChanged(ListSelectionEvent evt) {
Grade grade = (Grade)theJList.getSelectedValue();
if (grade == null) {
score.setText("");
possibleScore.setText("");
gradeType.setText("");
return;
score.setText(Double.toString(grade.getScore()));
possibleScore.setText(Double.toString(grade.getPossibleScore()));
gradeType.setText(grade.getGradeType());
//JLabel theLabel = new JLabel("Students");
jlistPanel = new JPanel(border3);
jlistPanel.setBorder(BorderFactory.createTitledBorder("List of Scores"));
jlistPanel.add(new JScrollPane(theJList));//, BorderLayout.SOUTH);
masterPanel = new JPanel(new GridLayout(1, 2));
masterPanel.setBorder(BorderFactory.createLineBorder(Color.black));
// masterPanel.add(Box.createHorizontalStrut(10));
masterPanel.add(infoPanel);
// masterPanel.add(Box.createHorizontalStrut(10));
masterPanel.add(jlistPanel);
// masterPanel.add(Box.createHorizontalStrut(10));
BorderLayout border = new BorderLayout();
this.getContentPane().setLayout(border);
Container theContainer = this.getContentPane();
theContainer.add(buttonPanel,BorderLayout.SOUTH);
theContainer.add(masterPanel, BorderLayout.CENTER);
// now add the event handlers for the buttons
AddHandler handleAdd = new AddHandler();
ModifyHandler handleModify = new ModifyHandler();
RemoveHandler handleRemove = new RemoveHandler();
add.addActionListener(handleAdd);
modify.addActionListener(handleModify);
remove.addActionListener(handleRemove);
// add the event handler for the window events
WindowHandler handleWindow = new WindowHandler();
this.addWindowListener(handleWindow);
setSize(600,300);
* Insert the method's description here.
* Creation date: (2/24/03 4:20:07 PM)
* @param v com.sun.java.util.collections.Vector
public void setStudentGrades(Vector v) {
studentGrades = v;
DefaultListModel model = (DefaultListModel) theJList.getModel();
model.removeAllElements();
int size = v.size();
for (int i = 0; i < size; i++) {
model.addElement(v.get(i));
score.setText("");
possibleScore.setText("");
gradeType.setText("");
setVisible(true);
// CODE2 StudentSystem
import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.*;
import java.awt.*;
* UsingJLists.java
* This is a sample program for the use of JLists. You can add a student by entering their
* information a clicking on add. You can remove a student by entering their information and
* clicking on remove. They must be in the list to be removed. You can modify a student by
* entering their information and clicking add. You will be asked for the new student
* information when using modify. The add and remove buttons will disappear when modifying
* is underway and the new information is being collected for updating.
* @author Delmarie
public class StudentSystem extends JFrame {
StudentGradeBook studentGradeBook = new StudentGradeBook();
GradeSystem gradeSystem = new GradeSystem(this, true);
JButton add, modify, remove, bGrade;
JList theJList;
JPanel buttonPanel, textPanel, labelPanel, masterPanel, jlistPanel, infoPanel;
JTextField name, address, email, phone, courseName, courseDescription;
JLabel label1, label2, label3;
StudentSystem tempObjectRef; // used to hold a class level reference to object for dispose
boolean getStudentInfo = false;
int saveIndexInObject;
public class ModifyHandler implements ActionListener {
public void actionPerformed(java.awt.event.ActionEvent actionEvent) {
// get the information for the student to modify
String studentName = name.getText();
String studentAddress = address.getText();
String studentEmail = email.getText();
if (!getStudentInfo) { // set up to get student info
// find the correct element of the model to remove and save in class variable
int removeIndex = -1;
DefaultListModel model = (DefaultListModel) theJList.getModel();
for (int i = 0; i < model.size(); i++) {
String temp = (String) model.elementAt(i);
if (temp.equals(name.getText())) {
removeIndex = i;
break;
saveIndexInObject = removeIndex;
if (removeIndex == -1) return;
// change the text on the border of the info box
infoPanel.setBorder(BorderFactory.createTitledBorder("Enter new Student Info"));
// set up to get the modified info and remove some of the buttons
getStudentInfo = true;
buttonPanel.removeAll();
buttonPanel.add(modify);
buttonPanel.add(bGrade);
buttonPanel.repaint();
else {
// reset the border and change the element at the provided index (from if above)
getStudentInfo = false;
infoPanel.setBorder(BorderFactory.createTitledBorder("Student Information"));
DefaultListModel model = (DefaultListModel) theJList.getModel();
model.setElementAt(name.getText(), saveIndexInObject);
Student student = studentGradeBook.findStudent(saveIndexInObject);
student.setName(name.getText());
student.setAddress(address.getText());
student.setEmail(email.getText());
student.setPhone(phone.getText());
student.setCourseName(courseName.getText());
student.setCourseDescription(courseDescription.getText());
// clear the textboxes
name.setText("");
address.setText("");
email.setText("");
phone.setText("");
courseName.setText("");
courseDescription.setText("");
// restore all of the buttons
buttonPanel.removeAll();
buttonPanel.add(add);
buttonPanel.add(modify);
buttonPanel.add(remove);
buttonPanel.add(bGrade);
buttonPanel.repaint();
public class RemoveHandler implements ActionListener {
public void actionPerformed(java.awt.event.ActionEvent actionEvent) {
// get the student info from the text boxes
String studentName = name.getText();
String studentAddress = address.getText();
String studentEmail = email.getText();
// find the element to remove by name (you could use email address etc also)
int removeIndex = -1; // = theJList.getSelectedIndex();
DefaultListModel model = (DefaultListModel) theJList.getModel();
for (int i = 0; i < model.size(); i++) {
String temp = (String) model.elementAt(i);
if (temp.equals(name.getText())) {
removeIndex = i;
break;
if (removeIndex == -1) return;
// remove the element at the index from the for loop
model.removeElementAt(removeIndex);
Student student = studentGradeBook.findStudent(removeIndex);
studentGradeBook.removeStudent(student);
// clear the textboxes
name.setText("");
address.setText("");
email.setText("");
phone.setText("");
courseName.setText("");
courseDescription.setText("");
public class AddHandler implements ActionListener {
public void actionPerformed(java.awt.event.ActionEvent actionEvent) {
// get the student info from the text boxes
String studentName = name.getText();
String studentAddress = address.getText();
String studentEmail = email.getText();
String studentPhone = phone.getText();
String studentCourseName = courseName.getText();
String studentCourseDescription = courseDescription.getText();
// get the model and add the student to the model
studentGradeBook.addStudent(studentName, studentAddress, studentEmail, studentPhone,
studentCourseName, studentCourseDescription);
DefaultListModel model = (DefaultListModel) theJList.getModel();
model.addElement(studentName);
// reset the text boxes
name.setText("");
address.setText("");
email.setText("");
phone.setText("");
courseName.setText("");
courseDescription.setText("");
public class WindowHandler extends WindowAdapter {
public void windowClosing(WindowEvent e) {
gradeSystem.dispose();
tempObjectRef.dispose();
System.exit(0);
/** Creates a new instance of UsingJLists */
public StudentSystem() {
// create all of the components, put them in panels, and put the panels in JFrame
add = new JButton("Add");
modify = new JButton("Modify");
remove = new JButton("Remove");
bGrade = new JButton("Grades");
name = new JTextField("");
name.setColumns(10);
address = new JTextField("");
email = new JTextField("");
phone = new JTextField("");
courseName = new JTextField("");
courseDescription = new JTextField("");
label1 = new JLabel("name");
label2 = new JLabel("address");
label3 = new JLabel("email");
JLabel label4 = new JLabel("phone");
JLabel label5 = new JLabel("courseName");
JLabel label6 = new JLabel("courseDescription");
FlowLayout flow = new FlowLayout();
FlowLayout flow1 = new FlowLayout();
FlowLayout flow2 = new FlowLayout();
GridLayout grid1 = new GridLayout(13,1);
GridLayout grid2 = new GridLayout(13,1);
BorderLayout border3 = new BorderLayout();
buttonPanel = new JPanel(flow);
buttonPanel.add(add);
buttonPanel.add(modify);
buttonPanel.add(remove);
buttonPanel.add(bGrade);
bGrade.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
int index = theJList.getSelectedIndex();
if (index == -1) return;
Student student = studentGradeBook.findStudent(index);
gradeSystem.setStudentGrades(student.getStudentGrades());
labelPanel = new JPanel(grid1);
//labelPanel.setBorder(BorderFactory.createLineBorder(Color.black));
labelPanel.add(Box.createVerticalStrut(20));
labelPanel.add(label1);
labelPanel.add(Box.createVerticalStrut(20));
labelPanel.add(label2);
labelPanel.add(Box.createVerticalStrut(20));
labelPanel.add(label3);
labelPanel.add(Box.createVerticalStrut(20));
labelPanel.add(label4);
labelPanel.add(Box.createVerticalStrut(20));
labelPanel.add(label5);
labelPanel.add(Box.createVerticalStrut(20));
labelPanel.add(label6);
labelPanel.add(Box.createVerticalStrut(20));
textPanel = new JPanel(grid2);
//textPanel.setBorder(BorderFactory.createLineBorder(Color.black));
textPanel.add(Box.createVerticalStrut(20));
textPanel.add(name);
textPanel.add(Box.createVerticalStrut(20));
textPanel.add(address);
textPanel.add(Box.createVerticalStrut(20));
textPanel.add(email);
textPanel.add(Box.createVerticalStrut(20));
textPanel.add(phone);
textPanel.add(Box.createVerticalStrut(20));
textPanel.add(courseName);
textPanel.add(Box.createVerticalStrut(20));
textPanel.add(courseDescription);
textPanel.add(Box.createVerticalStrut(20));
infoPanel = new JPanel(new FlowLayout());
infoPanel.setBorder(BorderFactory.createTitledBorder("Student Information"));
infoPanel.add(Box.createHorizontalStrut(10));
infoPanel.add(textPanel);
infoPanel.add(Box.createHorizontalStrut(10));
infoPanel.add(labelPanel);
infoPanel.add(Box.createHorizontalStrut(10));
theJList = new JList(new DefaultListModel());
theJList.addListSelectionListener(new javax.swing.event.ListSelectionListener(){
public void valueChanged(ListSelectionEvent evt) {
int index = theJList.getSelectedIndex();
if (index == -1) return;
Student student = studentGradeBook.findStudent(index);
name.setText(student.getName());
address.setText(student.getAddress());
email.setText(student.getEmail());
phone.setText(student.getPhone());
courseName.setText(student.getCourseName());
courseDescription.setText(student.getCourseDescription());
//JLabel theLabel = new JLabel("Students");
jlistPanel = new JPanel(border3);
jlistPanel.setBorder(BorderFactory.createTitledBorder("List of Students"));
jlistPanel.add(new JScrollPane(theJList), BorderLayout.SOUTH);
masterPanel = new JPanel(flow1);
masterPanel.setBorder(BorderFactory.createLineBorder(Color.black));
masterPanel.add(Box.createHorizontalStrut(10));
masterPanel.add(infoPanel);
masterPanel.add(Box.createHorizontalStrut(10));
masterPanel.add(jlistPanel);
masterPanel.add(Box.createHorizontalStrut(10));
BorderLayout border = new BorderLayout();
this.getContentPane().setLayout(border);
Container theContainer = this.getContentPane();
theContainer.add(buttonPanel,BorderLayout.SOUTH);
theContainer.add(masterPanel, BorderLayout.NORTH);
// now add the event handlers for the buttons
AddHandler handleAdd = new AddHandler();
ModifyHandler handleModify = new ModifyHandler();
RemoveHandler handleRemove = new RemoveHandler();
add.addActionListener(handleAdd);
modify.addActionListener(handleModify);
remove.addActionListener(handleRemove);
// add the event handler for the window events
WindowHandler handleWindow = new WindowHandler();
this.addWindowListener(handleWindow);
// make the frame visible and set its size and show it.
this.setVisible(true);
this.pack();//setSize(600,300);
this.show();
public static void main (String [] args) {
StudentSystem mainObject = new StudentSystem();
mainObject.setTempObjectRef(mainObject);
public void setTempObjectRef(StudentSystem obj) {
// set up a reference to this object for use in closing the window method dispose
tempObjectRef = obj;
// CODE 3 Student
import java.util.*;
* Insert the type's description here.
* Creation date: (2/24/03 11:23:58 AM)
* @author: Delmarie
public class Student {
private String name, address, phone, email, courseName, courseDescription;
private Vector studentGrades;
* Student constructor comment.
public Student() {
studentGrades = new Vector();
* Insert the method's description here.
* Creation date: (2/24/03 11:39:56 AM)
* @param score double
* @param possibleScore double
* @param gradeType java.lang.String
public void addGrade(double score, double possibleScore, String gradeType) {
Grade g = new Grade();
g.setScore(score);
g.setPossibleScore(possibleScore);
g.setGradeType(gradeType);
studentGrades.add(g);
* Insert the method's description here.
* Creation date: (2/24/03 11:47:01 AM)
* @return Grade
* @param index int
public Grade findGrade(int index) {
return (Grade)studentGrades.get(index);
* Insert the method's description here.
* Creation date: (2/24/03 11:28:57 AM)
* @return java.lang.String
public java.lang.String getAddress() {
return address;
* Insert the method's description here.
* Creation date: (2/24/03 11:28:57 AM)
* @return java.lang.String
public java.lang.String getCourseDescription() {
return courseDescription;
* Insert the method's description here.
* Creation date: (2/24/03 11:28:57 AM)
* @return java.lang.String
public java.lang.String getCourseName() {
return courseName;
* Insert the method's description here.
* Creation date: (2/24/03 11:28:57 AM)
* @return java.lang.String
public java.lang.String getEmail() {
return email;
* Insert the method's description here.
* Creation date: (2/24/03 11:48:03 AM)
* @return java.util.Iterator
public Iterator getGradeIterator() {
return studentGrades.iterator();
* Insert the method's description here.
* Creation date: (2/24/03 11:28:57 AM)
* @return java.lang.String
public java.lang.String getName() {
return name;
* Insert the method's description here.
* Creation date: (2/24/03 11:28:57 AM)
* @return java.lang.String
public java.lang.String getPhone() {
return phone;
* Insert the method's description here.
* Creation date: (2/25/03 10:56:13 AM)
* @return java.util.Vector
public java.util.Vector getStudentGrades() {
return studentGrades;
* Insert the method's description here.
* Creation date: (2/24/03 11:41:52 AM)
* @param grade Grade
public void removeGrade(Grade grade) {
studentGrades.remove(grade);
* Insert the method's description here.
* Creation date: (2/24/03 11:28:57 AM)
* @param newAddress java.lang.String
public void setAddress(java.lang.String newAddress) {
address = newAddress;
* Insert the method's description here.
* Creation date: (2/24/03 11:28:57 AM)
* @param newCourseDescription java.lang.String
public void setCourseDescription(java.lang.String newCourseDescription) {
courseDescription = newCourseDescription;
* Insert the method's description here.
* Creation date: (2/24/03 11:28:57 AM)
* @param newCourseName java.lang.String
public void setCourseName(java.lang.String newCourseName) {
courseName = newCourseName;
* Insert the method's description here.
* Creation date: (2/24/03 11:28:57 AM)
* @param newEmail java.lang.String
public void setEmail(java.lang.String newEmail) {
email = newEmail;
* Insert the method's description here.
* Creation date: (2/24/03 11:28:57 AM)
* @param newName java.lang.String
public void setName(java.lang.String newName) {
name = newName;
* Insert the method's description here.
* Creation date: (2/24/03 11:28:57 AM)
* @param newPhone java.lang.String
public void setPhone(java.lang.String newPhone) {
phone = newPhone;
* Insert the method's description here.
* Creation date: (2/25/03 10:56:13 AM)
* @param newStudentGrades java.util.Vector
public void setStudentGrades(Vector newStudentGrades) {
studentGrades = newStudentGrades;
//CODE 4 StudentGradeBook
import java.util.*;
* Insert the type's description here.
* Creation date: (2/24/03 11:50:35 AM)
* @author: delmarie
public class StudentGradeBook {
private Vector allStudents;
* StudentGradeBook constructor comment.
public StudentGradeBook() {
allStudents = new Vector();
* Insert the method's description here.
* Creation date: (2/24/03 11:54:01 AM)
* @param name java.lang.String
* @param address java.lang.String
* @param email java.lang.String
* @param phone java.lang.String
public void addStudent(String name, String address, String email, String phone) {
Student student = new Student();
student.setName(name);
student.setAddress(address);
student.setEmail(email);
student.setPhone(phone);
allStudents.add(student);
* Insert the method's description here.
* Creation date: (2/24/03 11:54:01 AM)
* @param name java.lang.String
* @param address java.lang.String
* @param email java.lang.String
* @param phone java.lang.String
public void addStudent(String name, String address, String email, String phone,
String courseName, String courseDescription) {
Student student = new Student();
student.setName(name);
student.setAddress(address);
student.setEmail(email);
student.setPhone(phone);
student.setCourseName(courseName);
student.setCourseDescription(courseDescription);
allStudents.add(student);
* Insert the method's description here.
* Creation date: (2/24/03 12:00:53 PM)
* @param index Student
public Student findStudent(int index) {
return (Student)allStudents.get(index);
* Insert the method's description here.
* Creation date: (2/24/03 12:02:43 PM)
* @return java.util.Iterator
public Iterator getStudentIterator() {
return allStudents.iterator();
* Insert the method's description here.
* Creation date: (2/24/03 11:59:41 AM)
* @param student Student
public void removeStudent(Student student) {
allStudents.remove(student);
// CODE 5 Grade
* Insert the type's description here.
* Creation date: (2/24/03 11:29:38 AM)
* @author: Delmarie
public class Grade {
private double score, possibleScore;
private String gradeType;
* Insert the method's description here.
* Creation date: (2/24/03 11:46:07 AM)
public Grade() {}
* Insert the method's description here.
* Creation date: (2/24/03 11:31:13 AM)
* @return java.lang.String
public java.lang.String getGradeType() {
return gradeType;
* Insert the method's description here.
* Creation date: (2/24/03 11:31:13 AM)
* @return double
public double getPossibleScore() {
return possibleScore;
* Insert the method's description here.
* Creation date: (2/24/03 11:31:13 AM)
* @return double
public double getScore() {
return score;
* Insert the method's description here.
* Creation date: (2/24/03 11:31:13 AM)
* @param newGradeType java.lang.String
public void setGradeType(java.lang.String newGradeType) {
gradeType = newGradeType;
* Insert the method's description here.
* Creation date: (2/24/03 11:31:13 AM)
* @param newPossibleScore double
public void setPossibleScore(double newPossibleScore) {
possibleScore = newPossibleScore;
* Insert the method's description here.
* Creation date: (2/24/03 11:31:13 AM)
* @param newScore double
public void setScore(double newScore) {
score = newScore;
* Insert the method's description here.
* Creation date: (2/24/03 4:03:57 PM)
* @return java.lang.String
public String toString() {
return Double.toString(score);Ok.
I had a look at your code and decided against showing you how to
modify it to do what you want....
Reason being that it's something of a mess. I guess the reason for that
mess is a combination of the fact that you're new to Java (new to
software in general?) and you're using Visual Age.
So, below is a very quick (far from perfect, I just knocked it up in my
lunch hour) example of the kind of approach I would take to the problem.
Feel free to take ideas from it and build them in to your code.
Whatever you do, don't hand it in as you own work. By all means, hand
it in in addition to your own work and maybe even get your
teacher to comment on it.
Oh yes, if you use it, chuck me some dukes form this and your earlier
post on the same subject. Too many folks these days are neglecting to
allocate dukes - don't be one of them!
Oh, one thing about using the app, double clicking on table entries
for students and grades brings up the appropriate dialog. To create
a new grade or delete the selected ones, use the "right mouse" context
menu.
Enjoy.
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.event.*;
import javax.swing.border.*;
import java.awt.event.*;
import java.awt.*;
import java.util.*;
import java.text.*;
public class Rosemary2
static class GradeDialog
extends JDialog
private JTextField mScore= new JTextField();
private JTextField mPossibleScore= new JTextField();
private JTextField mGradeType= new JTextField();
private Grade mGrade;
public GradeDialog(JDialog owner) { this(owner, null); }
public GradeDialog(JDialog owner, Grade grade)
super(owner, true);
mGrade= grade;
if (mGrade == null)
setTitle("New Grade");
else {
setTitle("Edit Grade");
setGrade();
JPanel panel= new JPanel();
panel.setBorder(new EmptyBorder(4,4,4,4));
panel.setLayout(new GridLayout(0,2,4,4));
panel.add(new JLabel("Score:"));
panel.add(mScore);
panel.add(new JLabel("Possible Score:"));
panel.add(mPossibleScore);
panel.add(new JLabel("Grade Type:"));
panel.add(mGradeType);
getContentPane().add(panel, BorderLayout.CENTER);
panel= new JPanel();
panel.setLayout(new GridLayout(1,0));
JButton ok= new JButton("OK");
panel.add(ok);
ok.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (scrapeGrade())
dispose();
JButton cancel= new JButton("Cancel");
panel.add(cancel);
cancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
mGrade= null;
dispose();
JPanel wrapper= new JPanel();
wrapper.setBorder(new EmptyBorder(0,4,4,4));
wrapper.setLayout(new BorderLayout());
wrapper.add(panel, BorderLayout.EAST);
getContentPane().add(wrapper, BorderLayout.SOUTH);
setResizable(false);
pack();
setLocation(
owner.getLocation().x +
(owner.getSize().width/2) -
(getSize().width/2),
owner.getLocation().y +
(owner.getSize().height/2) -
(getSize().height/2));
private void setGrade()
mScore.setText(String.valueOf(mGrade.getScore()));
mPossibleScore.setText(String.valueOf(mGrade.getPossibleScore()));
mGradeType.setText(mGrade.getGradeType());
mScore.selectAll();
private boolean scrapeGrade()
try {
if (mGrade == null) {
mGrade= new Grade(
Double.parseDouble(mScore.getText()),
Double.parseDouble(mPossibleScore.getText()),
mGradeType.getText());
else {
mGrade.setScore(Double.parseDouble(mScore.getText()));
mGrade.setPossibleScore(Double.parseDouble(mPossibleScore.getText()));
mGrade.setGradeType(mGradeType.getText());
return true;
catch (NumberFormatException e) {
JOptionPane.showMessageDialog(this, "Scores must be numbers, you Muppet!");
return false;
public Grade getGrade() { return mGrade; }
static class GradesPanel
extends JPanel
private Vector mGrades= new Vector();
private JTable mTable;
private NumberFormat mFormat= NumberFormat.getInstance();
private JDialog mParent;
public GradesPanel(JDialog parent, Iterator grades)
mParent= parent;
mFormat.setMaximumFractionDigits(2);
while (grades != null && grades.hasNext())
mGrades.add(grades.next());
setLayout(new BorderLayout());
setBorder(new EmptyBorder(4,4,4,4));
createTable();
JScrollPane sp= new JScrollPane(mTable);
add(sp, BorderLayout.CENTER);
MouseListener listener= new MouseAdapter() {
public void mousePressed(MouseEvent e) {
if (e.getButton() == e.BUTTON2 || e.getButton() == e.BUTTON3)
menu(e.getPoint());
mTable.addMouseListener(listener);
sp.addMouseListener(listener);
mTable.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() >= 2)
editGrade();
public Iterator getGrades() { return mGrades.iterator(); }
private void createTable()
mTable= new JTable(new AbstractTableModel() {
public int getColumnCount() {
return 4;
public int getRowCount() {
return mGrades.size();
public String getColumnName(int column) {
switch (column) {
case 0: return "Score";
case 1: return "Possible";
case 2: return "Type";
case 3: return "Grade";
default: return "###";
public Object getValueAt(int row, int column) {
Grade grade= (Grade) mGrades.elementAt(row);
switch (column) {
case 0: return mFormat.format(grade.getScore());
case 1: return mFormat.format(grade.getPossibleScore());
case 2: return grade.getGradeType();
case 3: return String.valueOf(grade.getGrade()) +"%";
default: return "###";
mTable.setPreferredScrollableViewportSize(new Dimension(10,10));
private void menu(Point point)
JPopupMenu popup= new JPopupMenu();
JMenuItem add= new JMenuItem("Add");
popup.add(add);
add.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { addGrade(); } });
if (mTable.rowAtPoint(point) >= 0 && mTable.rowAtPoint(point) == mTable.getSelectedRow()) {
JMenuItem edit= new JMenuItem("Edit");
popup.add(edit);
edit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { editGrade(); } });
if (mTable.getSelectedRowCount() > 1)
edit.setEnabled(false);
JMenuItem delete= new JMenuItem("Delete");
popup.add(delete);
delete.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { deleteGrade(); } });
popup.show(this, point.x, point.y);
private void addGrade()
GradeDialog dialog= new GradeDialog(mParent);
dialog.setVisible(true);
Grade grade= dialog.getGrade();
if (grade != null) {
mGrades.add(grade);
((AbstractTableModel) mTable.getModel()).fireTableRowsInserted(
mGrades.size()-1, mGrades.size()-1);
private void editGrade()
GradeDialog dialog= new GradeDialog(
mParent, (Grade) mGrades.get(mTable.getSelectedRow()));
dialog.setVisible(true);
if (dialog.getGrade() != null) {
((AbstractTableModel) mTable.getModel()).fireTableRowsUpdated(
mTable.getSelectedRow(), mTable.getSelectedRow());
private void deleteGrade()
while (true) {
int row= mTable.getSelectedRow();
if (row < 0)
break;
mGrades.removeElementAt(row);
((AbstractTableModel) mTable.getModel()).fireTableRowsDeleted(row, row);
static class StudentDialog
extends JDialog
private JTextField mName= new JTextField(12);
private JTextField mAddress= new JTextField();
private JTextField mPhone= new JTextField();
private JTextField mEmail= new JTextField();
private JTextField mCourseName= new JTextField();
private JTextField mCourseDescription= new JTextField();
private GradesPanel mGradesPanel;
private Student mStudent;
public StudentDialog(JFrame owner) { this(owner, null); }
public StudentDialog(JFrame owner, Student student)
super(owner, true);
mStudent= student;
if (mStudent == null) {
setTitle("New Student");
mGradesPanel= new GradesPanel(this, null);
else {
setTitle("Edit Student: " +mStudent.getName());
mGradesPanel= new GradesPanel(this, mStudent.getGrades());
JTabbedPane tab= new JTabbedPane();
tab.setBorder(new EmptyBorder(4,4,4,4));
getContentPane().add(tab, BorderLayout.CENTER);
tab.add("Details", getDetailsPanel());
tab.add("Grades", mGradesPanel);
JPanel panel= new JPanel();
panel.setLayout(new GridLayout(1,0));
JButton ok= new JButton("OK");
panel.add(ok);
ok.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
scrapeStudent();
dispose();
JButton cancel= new JButton("Cancel");
panel.add(cancel);
cancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
mStudent= null;
dispose();
JPanel wrapper= new JPanel();
wrapper.setBorder(new EmptyBorder(0,4,4,4));
wrapper.setLayout(new BorderLayout());
wrapper.add(panel, BorderLayout.EAST);
getContentPane().add(wrapper, BorderLayout.SOUTH);
setResizable(false);
pack();
if (mStudent != null)
setStudent();
setLocation(
owner.getLocation().x +
(owner.getSize().width/2) -
(getSize().width/2),
owner.getLocation().y +
(owner.getSize().height/2) -
(getSize().height/2));
private JPanel getDetailsPanel()
JPanel panel= new JPanel();
panel.setBorder(new EmptyBorder(4,4,4,4));
panel.setLayout(new GridLayout(0,2,4,4));
panel.add(new JLabel("Name:"));
panel.add(mName);
panel.add(new JLabel("Address:"));
panel.add(mAddress);
panel.add(new JLabel("Phone:"));
panel.add(mPhone);
panel.add(new JLabel("E-Mail:"));
panel.add(mEmail);
panel.add(new JLabel("Course Name:"));
panel.add(mCourseName);
panel.add(new JLabel("Course Description:"));
panel.add(mCourseDescription);
return panel;
private void setStudent()
mName.setEnabled(false);
mName.setText(mStudent.getName());
mAddress.setText(mStudent.getAddress());
mPhone.setText(mStudent.getPhone());
mEmail.setText(mStudent.getEmail());
mCourseName.setText(mStudent.getCourseName());
mCourseDescription.setText(mStudent.getCourseDescription());
private void scrapeStudent()
if (mStudent == null) {
mStudent= new Student(
mName.getText(),
mAddress.getText(),
mPhone.getText(),
mEmail.getText(),
mCourseName.getText(),
mCourseDescription.getText());
else {
mStudent.setName(mName.getText());
mStudent.setAddress(mAddress.getText());
mStudent.setPhone(mPhone.getText());
mStudent.setEmail(mEmail.getText());
mStudent.setCourseName(mCourseName.getText());
mStudent.setCourseDescription(mCourseDescription.getText());
mStudent.clearGrades();
Iterator grades= mGradesPanel.getGrades();
while (grades.hasNext())
mStudent.addGrade((Grade) grades.next());
public Student getStudent() { return mStudent; }
static class StudentFrame
extends JFrame
private Vector mStudents;
private JTable mTable;
private JButton mBtnEdit;
private JButton mBtnDelete;
public StudentFrame(Vector students)
super("Students");
mStudents= students;
createTable();
getContentPane().add(new JScrollPane(mTable), BorderLayout.CENTER);
JPanel panel= new JPanel();
panel.setLayout(new GridLayout(1,0));
JButton btn= new JButton("Add");
panel.add(btn);
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { addStudent(); } });
mBtnEdit= new JButton("Edit");
panel.add(mBtnEdit);
mBtnEdit.setEnabled(false);
mBtnEdit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { editStudent(); } });
mBtnDelete= new JButton("Delete");
panel.add(mBtnDelete);
mBtnDelete.setEnabled(false);
mBtnDelete.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { deleteStudent(); } });
JPanel wrapper= new JPanel();
wrapper.setLayout(new BorderLayout());
wrapper.add(panel, BorderLayout.WEST);
getContentPane().add(wrapper, BorderLayout.SOUTH);
btn= new JButton("Exit");
wrapper.add(btn, BorderLayout.EAST);
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { System.exit(0); } });
pack();
private void createTable()
mTable= new JTable(new AbstractTableModel() {
public int getColumnCount() {
return 7;
public int getRowCount() {
return mStudents.size();
public String getColumnName(int column) {
switch (column) {
case 0: return "Name";
case 1: return "Address";
case 2: return "Phone";
case 3: return "Email";
case 4: return "Course";
case 5: return "Description";
case 6: return "Grade Average";
default: return "###";
public Object getValueAt(int row, int column) {
Student student= (Student) mStudents.elementAt(row);
switch (column) {
case 0: return student.getName();
case 1: return student.getAddress();
case 2: return student.getPhone();
case 3: return student.getEmail();
case 4: return student.getCourseName();
case 5: return student.getCourseDescription();
case 6: return student.getGrade() >= 0 ? String.valueOf(student.getGrade()) +"%": "n/a";
default: return "###";
mTable.getSelectionModel().addListSelectionListener(
new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting())
return;
switch (mTable.getSelectedRowCount()) {
case 0:
mBtnEdit.setEnabled(false);
mBtnDelete.setEnabled(false);
break;
case 1:
mBtnEdit.setEnabled(true);
mBtnDelete.setEnabled(true);
break;
default:
mBtnEdit.setEnabled(false);
mBtnDelete.setEnabled(true);
break;
mTable.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() >= 2)
editStudent();
private void addStudent()
StudentDialog dialog= new StudentDialog(this);
dialog.setVisible(true);
Student student= dialog.getStudent();
if (student != null) {
mStudents.add(student);
((AbstractTableModel) mTable.getModel()).fireTableRowsInserted(
mStudents.size()-1, mStudents.size()-1);
private void editStudent()
StudentDialog dialog= new StudentDialog(
this, (Student) mStudents.get(mTable.getSelectedRow()));
dialog.setVisible(true);
if (dialog.getStudent() != null) {
((AbstractTableModel) mTable.getModel()).fireTableRowsUpdated(
mTable.getSelectedRow(), mTable.getSelectedRow());
private void deleteStudent()
while (true) {
int row= mTable.getSelectedRow();
if (row < 0)
break;
mStudents.removeElementAt(row);
((AbstractTableModel) mTable.getModel()).fireTableRowsDeleted(row, row);
static class Student
private String name;
private String address;
private String phone ;
private String email;
private String courseName;
private String courseDescription;
private Vector grades= new Vector();
public Student(
String name,
String address,
String phone,
String email,
String courseName,
String courseDescription)
setName(name);
setAddress(address);
setPhone(phone);
setEmail(email);
setCourseName(courseName);
setCourseDescription(courseDescription);
public Iterator getGrades() { return grades.iterator(); }
public void addGrade(Grade grade) { grades.add(grade); }
public void removeGrade(Grade grade) { grades.remove(grade); }
public void clearGrades() { grades.clear(); }
public int getGrade()
if (grades.size() == 0)
return -1;
int total= 0;
for (int i= 0; i< grades.size(); i++)
total += ((Grade) grades.get(i)).getGrade();
return (int) (total/grades.size());
public String getAddress() { return address; }
public void setAddress(String newAddress) { address = newAddress; }
public String getCourseDescription() { return courseDescription; }
public void setCourseDescription(String newCourseDescription) { courseDescription = newCourseDescription; }
public String getCourseName() { return courseName; }
public void setCourseName(String newCourseName) { courseName = newCourseName; }
public String getEmail() { return email; }
public void setEmail(String newEmail) { email = newEmail; }
public String getName() { return name; }
public void setName(String newName) { name = newName; }
public String getPhone() { return phone; }
public void setPhone(String newPhone) { phone = newPhone; }
static class Grade
private double score;
private double possibleScore;
private String gradeType;
public Grade(
double score,
double possibleScore,
String gradeType)
setScore(score);
setPossibleScore(possibleScore);
setGradeType(gradeType);
public int getGrade() { return (int) ((100/possibleScore)*score); }
public String getGradeType() { return gradeType; }
public void setGradeType(String newGradeType) { gradeType = newGradeType; }
public double getPossibleScore() { return possibleScore; }
public void setPossibleScore(double newPossibleScore) { possibleScore = newPossibleScore; }
public double getScore() { return score; }
public void setScore(double newScore) { score = newScore; }
public String toString() { return Double.toString(score); }
public static void main (String [] args)
Vector students= new Vector();
students.add(new Student(
"Fred Flitstone",
"6 Boulder Close, Bedrock",
"555 1234",
"[email protected]",
"Masonary 101",
"Elementary chipping bits off rocks"));
students.add(new Student(
"Barney Rubble",
"7 Boulder Close, Bedrock",
"555 6789",
"[email protected]",
"Masonary 101",
"Elementary chipping bits off rocks"));
for (int i= 0; i< 10; i++) {
Student student= new Student(
"Student " +i,
i +" Dorm St, Campus",
"555 1234",
"student" +i +"@college.edu",
"CS 101",
"CS for dummies");
student.addGrade(new Grade(Math.random()*100, 100.0, "Passing?"));
student.addGrade(new Grade(Math.random()*100, 100.0, "Failing?"));
students.add(student);
StudentFrame frame= new StudentFrame(students);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setBounds(32,32,640,480);
frame.setVisible(true);
} -
Hi guys, I need help in debugging this code I made, which is a GUI minesweeper. Its extremely buggy...I particularly need help fixing the actionListener part of the code as everytime I press a button on the GUI, an exception occurs.
help please!
package minesweeperGUI;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MinesweeperGUI implements ActionListener
//Declaration of attributes
static int length = 0;
JMenuItem menuItemNew = new JMenuItem();
JRadioButtonMenuItem rbEasy = new JRadioButtonMenuItem();
JRadioButtonMenuItem rbHard = new JRadioButtonMenuItem();
JMenuItem menuItemExit = new JMenuItem();
JButton buttonReset = new JButton();
JButton buttonGrid[][] = null;
JFrame frame = new JFrame();
int getBombsTotal = 0;
JLabel setBombsLabel = new JLabel();
int a = 0;
int b = 0;
//No constructor created. Uses default constructor
//Create the menu bar
public JMenuBar newMenuBar()
//Sets up the menubar
JMenuBar menuBar = new JMenuBar();
//Sets up the Game menu with choice of new, grid size, and exit
JMenu menu = new JMenu ("Game");
menuBar.add (menu);
menuItemNew = new JMenuItem ("New");
menuItemNew.addActionListener (this);
menu.add (menuItemNew);
menu.addSeparator();
//Sets up sub-menu for grid size with choice of easy and hard radio buttons
JMenu subMenu = new JMenu ("Grid Size");
rbEasy = new JRadioButtonMenuItem ("Easy: 5x5 grid");
rbEasy.addActionListener (this);
subMenu.add (rbEasy);
rbHard = new JRadioButtonMenuItem ("Hard: 10x10 grid");
rbHard.addActionListener (this);
subMenu.add (rbHard);
menu.add (subMenu);
menu.addSeparator();
menuItemExit = new JMenuItem ("Exit");
menuItemExit.addActionListener (this);
menu.add (menuItemExit);
return menuBar;
//Setting up of Bomb Grid
public int [][] setGrid (int length)
int grid[][] = null;
grid = new int[length][length];
for (int i = 0; i < length; i++)
for (int j = 0; j < length; j++)
grid[i][j] = ((int)Math.round(Math.random() * 10))% 2;
return grid;
//Setting up of the of the graphical bomb grid
public JButton[][] setButtonGrid (int length)
JButton buttonGrid[][] = null;
buttonGrid = new JButton[length][length];
for (int i = 0; i < length; i++)
for (int j = 0; j < length; j++)
buttonGrid[i][j] = new JButton();
return buttonGrid;
//Setting up of a way to count the total number of bombs in the bomb grid
public int getBombsTotal (int length, int setGrid[][])
int bombsTotal = 0;
for (int i = 0; i < length; i++)
for (int j = 0; j < length; j++)
if (setGrid[i][j] == 1)
bombsTotal += 1;
return bombsTotal;
//Create a label for number of bombs left
public JLabel setBombsLabel (int getBombsTotal)
JLabel bombsLabel = new JLabel(String.valueOf (getBombsTotal) + " Bombs Left");
return bombsLabel;
//Setting up a way to count the number of bombs around a button
public String setBombs (int length, int setGrid[][], int x, int y)
int bombs[][] = new int[length][length];
String bombsString = null;
for (int i = 0; i < length; i++)
for (int j = 0; j < length; j++)
if (i == 0 && j == 0)
bombs[i][j] = setGrid[i][j+1] + setGrid[i+1][j] +
setGrid[i+1][j+1];
else if (i ==0 && j == (length - 1))
bombs[i][j] = setGrid[i][j-1] + setGrid[i+1][j-1] +
setGrid[i+1][j];
else if (i == (length - 1) && j == 0)
bombs[i][j] = setGrid[i-1][j] + setGrid[i-1][j+1] +
setGrid[i][j+1];
else if (i == (length - 1) && j == (length - 1))
bombs[i][j] = setGrid[i-1][j-1] + setGrid[i-1][j] +
setGrid[i][j-1];
else if (i == 0 && j != 0 && j != (length - 1))
bombs[i][j] = setGrid[i][j-1] + setGrid[i][j+1] +
setGrid[i+1][j-1] + setGrid[i+1][j] +
setGrid[i+1][j+1];
else if (i == (length - 1) && j != 0 && j != (length - 1))
bombs[i][j] = setGrid[i-1][j-1] + setGrid[i-1][j] +
setGrid[i-1][j+1] + setGrid[i][j-1] +
setGrid[i][j+1];
else if (i != 0 && i != (length - 1) && j == 0)
bombs[i][j] = setGrid[i-1][j] + setGrid[i-1][j+1] +
setGrid[i][j+1] + setGrid[i+1][j] +
setGrid[i+1][j+1];
else if (i != 0 && i != (length - 1) && j == (length - 1))
bombs[i][j] = setGrid[i-1][j-1] + setGrid[i-1][j] +
setGrid[i][j-1] + setGrid[i+1][j-1] +
setGrid[i+1][j];
else
bombs[i][j] = setGrid[i-1][j-1] + setGrid[i-1][j] +
setGrid[i-1][j+1] + setGrid[i][j-1] +
setGrid[i][j+1] + setGrid[i+1][j-1] +
setGrid[i+1][j] + setGrid[i+1][j+1];
bombsString = String.valueOf (bombs[x][y]);
return bombsString;
//create the panel for the bombs label and reset button
public JPanel newTopPanel(int length)
int setGridNew [][] = null;
setGridNew = new int[length][length];
int getBombsTotalNew = 0;
JLabel setBombsLabelNew = new JLabel();
setGridNew = setGrid (length);
getBombsTotalNew = getBombsTotal (length, setGridNew);
setBombsLabelNew = setBombsLabel (getBombsTotalNew);
JPanel topPanel = new JPanel ();
topPanel.setLayout (new BorderLayout (50,50));
JLabel bombsLabel = new JLabel ();
bombsLabel = setBombsLabelNew;
topPanel.add (bombsLabel, BorderLayout.WEST);
buttonReset = new JButton("Reset");
buttonReset.addActionListener (this);
topPanel.add (buttonReset, BorderLayout.CENTER);
return topPanel;
//create the panel for the play grids
public JPanel newBottomPanel(int length)
JButton setButtonGridNew[][] = null;
setButtonGridNew = new JButton [length][length];
setButtonGridNew = setButtonGrid (length);
JPanel bottomPanel = new JPanel ();
bottomPanel.setLayout (new GridLayout (length, length));
buttonGrid = new JButton[length][length];
for (a = 0; a < length; a++)
for (b = 0; b < length; b++)
buttonGrid[a] = setButtonGridNew[a][b];
buttonGrid[a][b].addActionListener (this);
bottomPanel.add (buttonGrid[a][b]);
return bottomPanel;
//Overiding of abstract method actionPerformed
public void actionPerformed(ActionEvent e)
if (e.getSource() == menuItemNew)
launchFrame(length);
else if (e.getSource() == menuItemExit)
frame.setVisible (false);
System.exit(0);
else if (e.getSource() == rbEasy)
length = 5;
launchFrame(length);
else if (e.getSource() == rbHard)
length = 10;
launchFrame(length);
else if (e.getSource() == buttonReset)
launchFrame(length);
else if (e.getSource() == buttonGrid[a][b])
int setGridNew [][] = null;
setGridNew = new int[length][length];
JButton bombButton [][] = null;
bombButton = new JButton [length][length];
String bombString [][] = null;
bombString = new String[length][length];
setGridNew = setGrid (length);
bombString[a][b] = setBombs (length, setGridNew, a, b);
bombButton[a][b] = new JButton (bombString[a][b]);
if (setGridNew[a][b] == 0)
buttonGrid[a][b] = bombButton[a][b];
getBombsTotal--;
JLabel setBombsLabelNew = new JLabel();
setBombsLabelNew = setBombsLabel (getBombsTotal);
else if (setGridNew[a][b] == 1 )
buttonGrid[a][b] = new JButton("x");
JOptionPane.showMessageDialog (null, "Game Over. You hit a Bomb!");
System.exit(0);
//create the content pane
public Container newContentPane(int length)
JPanel topPanel = new JPanel();
JPanel bottomPanel = new JPanel();
topPanel = newTopPanel(length);
bottomPanel = newBottomPanel (length);
JPanel contentPane = new JPanel();
contentPane.setOpaque (true);
contentPane.setLayout (new BorderLayout(50,50));
contentPane.add (topPanel, BorderLayout.NORTH);
contentPane.add (bottomPanel, BorderLayout.CENTER);
return contentPane;
public void launchFrame (int length)
//Makes sure we have nice window decorations
JFrame.setDefaultLookAndFeelDecorated(true);
//Sets up the top-level window
frame = new JFrame ("Minesweeper");
//Exits program when the closed button is clicked
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
JMenuBar menuBar = new JMenuBar();
Container contentPane = new Container();
menuBar = newMenuBar();
contentPane = newContentPane (length);
//Sets up the menu bar and content pane
frame.setJMenuBar (menuBar);
frame.setContentPane (contentPane);
//Displays the window
frame.pack();
frame.setVisible (true);
public static void main (String args[])
//Default length is 5
length = 5;
MinesweeperGUI minesweeper = new MinesweeperGUI();
minesweeper.launchFrame(length);hi, thanks. that removed the exception; although now the buttons action listener won't work :(
here is the revised code:
To anyone out there, can you guys run this code and help me debug it?
I'm really desperate as this is a school project of mine and the deadline is 7 hours away. I have already been working on it for 3 days, but the program is still very buggy.
thanks!
/* Oliver Ian C. Wee 04-80112
* CS12 MHRU
* Machine Problem 2
package minesweeperGUI;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MinesweeperGUI implements ActionListener
//Declaration of attributes
static int length = 0;
JMenuItem menuItemNew = new JMenuItem();
JRadioButtonMenuItem rbEasy = new JRadioButtonMenuItem();
JRadioButtonMenuItem rbHard = new JRadioButtonMenuItem();
JMenuItem menuItemExit = new JMenuItem();
JButton buttonReset = new JButton();
JButton buttonGrid[][] = null;
JFrame frame = new JFrame();
int getBombsTotal = 0;
JLabel setBombsLabel = new JLabel();
int a = 0;
int b = 0;
//No constructor created. Uses default constructor
//Create the menu bar
public JMenuBar newMenuBar()
//Sets up the menubar
JMenuBar menuBar = new JMenuBar();
//Sets up the Game menu with choice of new, grid size, and exit
JMenu menu = new JMenu ("Game");
menuBar.add (menu);
menuItemNew = new JMenuItem ("New");
menuItemNew.addActionListener (this);
menu.add (menuItemNew);
menu.addSeparator();
//Sets up sub-menu for grid size with choice of easy and hard radio buttons
JMenu subMenu = new JMenu ("Grid Size");
ButtonGroup bg = new ButtonGroup();
rbEasy = new JRadioButtonMenuItem ("Easy: 5x5 grid");
bg.add (rbEasy);
rbEasy.addActionListener (this);
subMenu.add (rbEasy);
rbHard = new JRadioButtonMenuItem ("Hard: 10x10 grid");
bg.add (rbHard);
rbHard.addActionListener (this);
subMenu.add (rbHard);
menu.add (subMenu);
menu.addSeparator();
menuItemExit = new JMenuItem ("Exit");
menuItemExit.addActionListener (this);
menu.add (menuItemExit);
return menuBar;
//Setting up of Bomb Grid
public int [][] setGrid (int length)
int grid[][] = null;
grid = new int[length][length];
for (int i = 0; i < length; i++)
for (int j = 0; j < length; j++)
grid[i][j] = ((int)Math.round(Math.random() * 10))% 2;
return grid;
//Setting up of the of the graphical bomb grid
public JButton[][] setButtonGrid (int length)
JButton buttonGrid[][] = null;
buttonGrid = new JButton[length][length];
for (int i = 0; i < length; i++)
for (int j = 0; j < length; j++)
buttonGrid[i][j] = new JButton();
return buttonGrid;
//Setting up of a way to count the total number of bombs in the bomb grid
public int getBombsTotal (int length, int setGrid[][])
int bombsTotal = 0;
for (int i = 0; i < length; i++)
for (int j = 0; j < length; j++)
if (setGrid[i][j] == 1)
bombsTotal += 1;
return bombsTotal;
//Create a label for number of bombs left
public JLabel setBombsLabel (int getBombsTotal)
JLabel bombsLabel = new JLabel(" " +String.valueOf (getBombsTotal) + " Bombs Left");
return bombsLabel;
//Setting up a way to count the number of bombs around a button
public String setBombs (int length, int setGrid[][], int x, int y)
int bombs[][] = new int[length][length];
String bombsString = null;
for (int i = 0; i < length; i++)
for (int j = 0; j < length; j++)
if (i == 0 && j == 0)
bombs[i][j] = setGrid[i][j+1] + setGrid[i+1][j] +
setGrid[i+1][j+1];
else if (i ==0 && j == (length - 1))
bombs[i][j] = setGrid[i][j-1] + setGrid[i+1][j-1] +
setGrid[i+1][j];
else if (i == (length - 1) && j == 0)
bombs[i][j] = setGrid[i-1][j] + setGrid[i-1][j+1] +
setGrid[i][j+1];
else if (i == (length - 1) && j == (length - 1))
bombs[i][j] = setGrid[i-1][j-1] + setGrid[i-1][j] +
setGrid[i][j-1];
else if (i == 0 && j != 0 && j != (length - 1))
bombs[i][j] = setGrid[i][j-1] + setGrid[i][j+1] +
setGrid[i+1][j-1] + setGrid[i+1][j] +
setGrid[i+1][j+1];
else if (i == (length - 1) && j != 0 && j != (length - 1))
bombs[i][j] = setGrid[i-1][j-1] + setGrid[i-1][j] +
setGrid[i-1][j+1] + setGrid[i][j-1] +
setGrid[i][j+1];
else if (i != 0 && i != (length - 1) && j == 0)
bombs[i][j] = setGrid[i-1][j] + setGrid[i-1][j+1] +
setGrid[i][j+1] + setGrid[i+1][j] +
setGrid[i+1][j+1];
else if (i != 0 && i != (length - 1) && j == (length - 1))
bombs[i][j] = setGrid[i-1][j-1] + setGrid[i-1][j] +
setGrid[i][j-1] + setGrid[i+1][j-1] +
setGrid[i+1][j];
else
bombs[i][j] = setGrid[i-1][j-1] + setGrid[i-1][j] +
setGrid[i-1][j+1] + setGrid[i][j-1] +
setGrid[i][j+1] + setGrid[i+1][j-1] +
setGrid[i+1][j] + setGrid[i+1][j+1];
bombsString = String.valueOf (bombs[x][y]);
return bombsString;
//create the panel for the bombs label and reset button
public JPanel newTopPanel(int length)
int setGridNew [][] = null;
setGridNew = new int[length][length];
int getBombsTotalNew = 0;
JLabel setBombsLabelNew = new JLabel();
setGridNew = setGrid (length);
getBombsTotalNew = getBombsTotal (length, setGridNew);
setBombsLabelNew = setBombsLabel (getBombsTotalNew);
JPanel topPanel = new JPanel ();
topPanel.setLayout (new BorderLayout (20,20));
JLabel bombsLabel = new JLabel ();
bombsLabel = setBombsLabelNew;
topPanel.add (bombsLabel, BorderLayout.WEST);
buttonReset = new JButton("Reset");
buttonReset.addActionListener (this);
topPanel.add (buttonReset, BorderLayout.CENTER);
return topPanel;
//create the panel for the play grids
public JPanel newBottomPanel(int length)
JButton setButtonGridNew[][] = null;
setButtonGridNew = new JButton [length][length];
setButtonGridNew = setButtonGrid (length);
JPanel bottomPanel = new JPanel ();
bottomPanel.setLayout (new GridLayout (length, length));
buttonGrid = new JButton[length][length];
for (int i = 0; i < length; i++)
for (int j = 0; j < length; j++)
buttonGrid[i][j] = setButtonGridNew[i][j];
buttonGrid[i][j].addActionListener (this);
bottomPanel.add (buttonGrid[i][j]);
return bottomPanel;
//Overiding of abstract method actionPerformed
public void actionPerformed(ActionEvent e)
if (e.getSource() == menuItemNew)
closeFrame();
launchFrame(length);
else if (e.getSource() == menuItemExit)
frame.setVisible (false);
System.exit(0);
else if (e.getSource() == rbEasy)
closeFrame();
length = 5;
launchFrame(length);
else if (e.getSource() == rbHard)
closeFrame();
length = 10;
launchFrame(length);
else if (e.getSource() == buttonReset)
closeFrame();
launchFrame(length);
else if (e.getSource() == buttonGrid[a])
int setGridNew [][] = null;
setGridNew = new int[length][length];
JButton bombButton [][] = null;
bombButton = new JButton [length][length];
String bombString [][] = null;
bombString = new String[length][length];
setGridNew = setGrid (length);
for (int i = 0; i < length; i++)
for (int j = 0; j < length; j++)
bombString[i][j] = setBombs (length, setGridNew, i, j);
bombButton[i][j] = new JButton (bombString[i][j]);
if (setGridNew[a][b] == 0)
buttonGrid[a][b] = bombButton[a][b];
getBombsTotal--;
JLabel setBombsLabelNew = new JLabel();
setBombsLabelNew = setBombsLabel (" " String.valueOf (getBombsTotal) " Bombs Left");
else if (setGridNew[a][b] == 1 )
buttonGrid[a][b] = new JButton("x");
JOptionPane.showMessageDialog (null, "Game Over. You hit a Bomb!");
System.exit(0);
//create the content pane
public Container newContentPane(int length)
JPanel topPanel = new JPanel();
JPanel bottomPanel = new JPanel();
topPanel = newTopPanel(length);
bottomPanel = newBottomPanel (length);
JPanel contentPane = new JPanel();
contentPane.setOpaque (true);
contentPane.setLayout (new BorderLayout(5,5));
contentPane.add (topPanel, BorderLayout.NORTH);
contentPane.add (bottomPanel, BorderLayout.CENTER);
return contentPane;
public void closeFrame ()
frame = new JFrame ("Minesweeper");
frame.dispose();
public void launchFrame (int length)
//Makes sure we have nice window decorations
JFrame.setDefaultLookAndFeelDecorated(true);
//Sets up the top-level window
frame = new JFrame ("Minesweeper");
//Exits program when the closed button is clicked
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
JMenuBar menuBar = new JMenuBar();
Container contentPane = new Container();
menuBar = newMenuBar();
contentPane = newContentPane (length);
//Sets up the menu bar and content pane
frame.setJMenuBar (menuBar);
frame.setContentPane (contentPane);
//Displays the window
frame.pack();
frame.setVisible (true);
public static void main (String args[])
//Default length is 5
length = 5;
MinesweeperGUI minesweeper = new MinesweeperGUI();
minesweeper.launchFrame(length); -
VT01n,VT02n ...Need user exit or Badi to implement this code :
Hi Experts ,
In VT01n or VT02n transactions , when I give shipping type as 03 (VTTK-VSART) and TransportPlanPt as 4701 (VTTK-TPLST) , the additional data tab field Suppl. 1 (VTTK-ADD01) must be filled with Z1 value automatically , Even though if the value is not given in additional data tab field Suppl 1 by the user. In which user exit or Badi shall i write my code ???
After saving , I must get Suppl. 1 (VTTK-ADD01) as Z1 ,.
Please suggest User exit or Badi with importing and exporting parameter's as VTTK table or any other solution to achieve this .
Note : Table VTADD01 already has this value Z1 .
Thanks All !!!There are enhancements you can make for Shipments in transaction CMOD. Create a new project. Then you need to add enhancement(s) to the project. Look at the enhancements starting with V56. I think enhancement V56USVDP will work for what you want to do. After the enhancement(s) have been added to the project, then click on the Components button. You will see a list of function modules. Sometimes there is documentation available using the blue i button on the screen. Double click the function module you want to change. There is also documentation available in the function module sometimes. Double click the Z include in the function module. You will have to create the include. Then you can make the necessary changes in the Z include. After you have made your code changes, you have to go back to the component screen and activate the enhancement component. The activate function is in the menu under the project menu.
Hope it helps,
Brian
Maybe you are looking for
-
Levaraging LDAP in BO XI 3.1
Hello Experts, I have a requirement from my cllient, to levarage BOE LDAP with existing LDAP of SAP PORTAL..could any one let me know the process of levaraging LDAP in BO. Complete issue details, If SAP Enterprise portal LDAP is isuuing tickets for
-
**Running Windows Vista 6.0 SP1 with Firefox 6.0.2
-
Print from iphones on Officejet 8600 too large
a problem has suddenly popped up on our Officejet Pro 8600; when printing to the printer over the wireless network with our iphones or ipads, the output is extremely large. we have tried resetting the printer, resetting each phone and ipad. the out
-
Post Author: lhs822 CA Forum: Formula Hi, I am new to Crystal Reports, but I have a report written and I would like to add 3 formula fields at the bottom to show whether the performance as late, on-time, or early. Here is an example: The detail of th
-
I noticed that when I tried importing songs to iTunes (unprotected) either via "Add File to Library" or "Automatically add to iTunes", only the first 30 characters of the song title is copied over to iTunes. Is there a way to change this? Is this a d