Int ?

Hi!
I got this error, when using int, I believe that is the reason anyway,. Do i miss something there in the beginning?
Where on the net can I found which things is inluded in which "library"? (Like that i need javax.swing.*; for a dialogbox(JOptionPane)
Klas
import java.text.*;
import java.lang.Math;
import javax.swing.*;
public class uppg3_3{ 
E:\Program\Xinox Software\JCreator LE\MyProjects\uppg3_3.java:15: incompatible types
found : java.lang.String
required: int
ar=JOptionPane.showInputDialog("�r 1940-2002 :");
(ar is an int)

LE\MyProjects\uppg3_3.java:15: incompatible types
found : java.lang.String
required: int
ar=JOptionPane.showInputDialog("�r 1940-2002 :");
(ar is an int)JOptionPane.showInputDialog(String) returns a String, but your variable is an int. If you are expecting the input to be a number, then you must check that it is a number, and convert it accordingly. If you are absoloutely certain that the input is a number, then you can use
ar = Integer.parseInt(JOptionPane.showInputDialog("..."));

Similar Messages

  • Can not refresh data int the report...

    Application on C#.
    Steps:
    1. Get Report without data from the database
    2. Change the dataconnections in report to the current user
    3. refresh data on the report (FilePath = TempFilePath)
    4. Resave report file with data
    5. Automatically open CrystalReportsViewer2008 and load the report
    Result
    On developer machine is allright, but on the user machine data isn't refreshed. Therefore CrysrtalReportsViewer2008 can't open report. It say that check the SaveDatawithReport parameter.
    In process  I found that in temp directory on user pc, didn't creates some temprorary files which creates on developer PC. Why? Help me please.
    Sorry for my English.

    There is the code of my programm
    function ParseReport is refreshed the data and change dataconnections for current user
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SqlClient;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.IO;
    using System.Diagnostics;
    using CRApp;
    using Microsoft.Win32;
    namespace CRApp
         * u041Au043Bu0430u0441u0441 u0434u043Bu044F u0430u0432u0442u043Eu043Cu0430u0442u0438u0437u0438u0440u043Eu0432u0430u043Du043Du043Eu0433u043E u0432u0438u0437u0443u0430u043Bu044Cu043Du043Eu0433u043E u0434u043Eu0441u0442u0443u043Fu0430
         * u043A u0444u0430u0439u043Bu0430u043C u0448u0430u0431u043Bu043Eu043Du043Eu0432, u0441u0433u0435u043Du0435u0440u0438u0440u043Eu0432u0430u043Du043Du044Bu0445 u0432
         * u043Fu0440u043Eu0433u0440u0430u043Cu043Cu0435 Crystal Reports
        public partial class Export2CR_MForm : Form
            public Export2CR_MForm()
                InitializeComponent();
                Start();
            public void Start()
                LoginForm Login = new LoginForm();
                DialogResult Dres = Login.ShowDialog();
                if (Dres == DialogResult.OK)
                    if (Login.GetConStr().ToString() != "")
                        GetReportNamesFromDataBase(Login.GetConStr());
                        SetConnectionString(Login.GetConStr());
                        this.CenterToScreen();
                        Visible = true;
                        Login.Close();
                else
                    Login.Close();
                    this.CenterToScreen();
                    this.OnClosed(null);
                 * u041Fu043Eu043Bu0443u0447u0430u0435u043C u043Fu0443u0442u044C u043A u0432u0440u0435u043Cu0435u043Du043Du044Bu043C u0444u0430u0439u043Bu0430u043C
                TempFilePath = Path.GetTempPath();
             * u041Au0440u0438u0441u0442u0430u043Bu043Eu0432u0441u043Au0438u0439 u0432u044Cu044Eu0432u0435u0440u043Eu043A
            CrystalDecisions.Windows.Forms.CrystalReportViewer viewer;
             * u041Fu0443u0442u044C u043A u0432u0440u0435u043Cu0435u043Du043Du043Eu0439 u043Fu0430u043Fu043Au0435
            private string TempFilePath;
             * u041Fu0430u0440u0430u043Cu0435u0442u0440 u0437u0430u043Fu0438u0441u0438 u0432 u0440u0435u0436u0438u043Cu0435, u0442u0430u0431u043Bu0438u0446u0435 (u0438u0442u0434...)
             * u041Du0443u0436u0435u043D u0434u043Bu044F u0442u043Eu0433u043E u0447u0442u043Eu0431u044B u0432u044Bu0431u0438u0440u0430u0442u044C
             * u043Eu043Fu0435u0440u0435u0434u043Bu0451u043Du043Du044Bu0439 u0434u0430u0442u0430u0441u0435u0442, u0441u043Eu043Eu0442u0432u0435u0442u0441u0442u0432u0443u044Eu0449u0438u0439 u0432u044Bu0431u0440u0430u043Du043Du043Eu0439 u0437u0430u043Fu0438u0441u0438
            private int ObjectIDOfTemplate;
             * u0423u0441u0442u0430u043Du043Eu0432u043Au0430 u0437u043Du0430u0447u0435u043Du0438u044F ObjectIDOfTemplate
            public void SetObjectIDOfTemplate(int /*
                                                   * ObjectID u0442u043Eu0433u043E u0448u0430u0431u043Bu043Eu043Du0430,
                                                   * u043Au043Eu0442u043Eu0440u044Bu0439 u043Du0430u0434u043E u043Fu043Eu043Bu0443u0447u0438u0442u044C
                                                      EnternalObjectID)
                ObjectIDOfTemplate = EnternalObjectID;
             * u041Fu043Eu043Bu0443u0447u0438u0442u044C ObjectID u0448u0430u0431u043Bu043Eu043Du0430
             * u0441 u043Au043Eu0442u043Eu0440u044Bu043C u0440u0430u0431u043Eu0442u0430u043Bu0438 u0434u043Bu044F
             * u0438u0441u043Fu043Eu043Bu044Cu0437u043Eu0432u0430u043Du0438u044F u0435u0433u043E u0432u043Du0435 u0431u0438u0431u043Bu0438u043Eu0442u0435u043Au0438
            public int GetObjectIDOfTemplate()
                return ObjectIDOfTemplate;
             * u041Fu0443u0442u044C u043A u0432u044Bu043Fu043Bu044Eu043Du0443u0442u043Eu043Cu0443 u0444u0430u0439u043Bu0443
            private string TemplateFilePath;
             * u0423u0441u0442u0430u043Du043Eu0432u0438u0442u044C u043Fu0443u0442u044C u043A
             * u0432u044Bu043Fu043Bu044Eu043Du0443u0442u043Eu043Cu0443 u0444u0430u0439u043Bu0443
            public void SetTemplateFilePath(string In)
                TemplateFilePath = In;
             * u041Fu043Eu043Bu0443u0447u0438u0442u044C u043Fu0443u0442u044C u043A
             * u0432u044Bu043Fu043Bu044Eu043Du0443u0442u043Eu043Cu0443 u0444u0430u0439u043Bu0443
            public string GetTemplateFilePath()
                return TemplateFilePath;
             * u0424u0443u043Du043Au0446u0438u044F u043Eu0442u043Au0440u044Bu0442u0438u044F u0444u0430u0439u043Bu0430,
             * u043Fu043Eu043Bu0443u0447u0435u043Du043Du043Eu0433u043E u0438u0437 u0431u0430u0437u044B u0438
             * u043Fu043Eu043Bu043Eu0436u0435u043Du043Du043Eu0433u043E u0432u043E u0432u0440u0435u043Cu0435u043Du043Du0443u044E u043Fu0430u043Fu043Au0443
            public int ParseReport(string FilePath)
                viewer = new CrystalDecisions.Windows.Forms.CrystalReportViewer();
                CrystalDecisions.CrystalReports.Engine.ReportDocument rd =
                    new CrystalDecisions.CrystalReports.Engine.ReportDocument();
                try
                    rd.Load(FilePath);
                    try
                        for (int i = 0; i < rd.DataSourceConnections.Count; i++)
                            rd.DataSourceConnections<i>.SetConnection(
                                GetConnectionString().GetServerName(),
                                GetConnectionString().GetDatabaseName(),
                                GetConnectionString().GetUserName(),
                                GetConnectionString().GetPassword()
                            for (int j = 0; j < rd.Database.Tables.Count; j++)
                                DataTable dataSet = new DataTable();
                                SqlConnection C = new SqlConnection(GetConnectionString().ToString());
                                string ViewName = GetDataViewName(GetConnectionString(), ParseTableName(
                                                rd.Database.Tables[j].Name));
                                SqlCommand Q = new SqlCommand("select * from " + ViewName
                                    , C);
                                Q.CommandType = CommandType.Text;
                                SqlDataAdapter adapter = new SqlDataAdapter();
                                adapter.SelectCommand = Q;
                                adapter.Fill(dataSet);
                                rd.Database.Tables[j].SetDataSource(dataSet);
                    catch (Exception e)
                        MessageBox.Show(e.Message);
                    try
                        SetTemplateFilePath(TempFilePath + "\\" + FileTreeView.SelectedNode.Text.ToString() + ".rpt");
                        rd.ReportOptions.EnableSaveDataWithReport = true;
                        viewer.ReportSource = rd;
                        viewer.RefreshReport();
                        rd.SaveAs(TemplateFilePath);
                        rd.Close();
                        return 0;
                    catch (Exception e)
                        MessageBox.Show(e.Message);
                        return -1;
                catch (Exception ex)
                    rd.ReportOptions.EnableUseDummyData = true;
                    rd.ReportOptions.EnableSaveDataWithReport = true;
                    viewer.RefreshReport();
                    rd.SaveAs(TemplateFilePath);
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                    return -1;
             * u0420u0430u0437u0431u0438u0435u043Du0438u0435 u0438u043Cu0435u043Du0438 u0442u0430u0431u043Bu0438u0446u044B
             * u0434u043Bu044F u043Fu043Eu043Bu0443u0447u0435u043Du0438u044F u043Du043Eu043Cu0435u0440u0430 u043Au043Bu0430u0441u0441u0430
            public string ParseTableName(string TableName)
    //            MessageBox.Show(TableName);
                int x = 0;
                if (TableName.Contains("Class"))
                    x = TableName.LastIndexOf("s");
                    return TableName.Remove(0,x+1);
                if(TableName.Contains("Attr"))
                    x = TableName.IndexOf("r");
    //           MessageBox.Show(x.ToString());
    //           MessageBox.Show(TableName.Remove(0, x+1));
                return TableName.Remove(0, x+1);
             * u0424u0443u043Du043Au0446u0438u044F u043Fu043Eu043Bu0443u0447u0435u043Du0438u044F u0444u0430u0439u043Bu0430 u0438u0437 u0431u0430u0437u044B
            public int ParseReportWithDataBase()
                try
                    string ConnectionString = GetConnectionString().ToString();               
                    SqlConnection C = new SqlConnection(ConnectionString);
                    C.Open();
                    string SelectString = "select P119 from "+ GetDataViewName(GetConnectionString(),"24") +" where P115='";
                    SelectString = SelectString+FileTreeView.SelectedNode.Text.ToString()+"'";
                    SqlCommand Q = new SqlCommand(SelectString, C);
                    Q.CommandType = CommandType.Text;
                    SqlDataAdapter adapter = new SqlDataAdapter();
                    adapter.SelectCommand = Q;
                    DataTable table = new DataTable();
                    adapter.Fill(table);
                    byte[] b = (byte[])table.Rows[0].ItemArray.GetValue(0);
                    FileStream fs = File.Create(TempFilePath+"\\"+FileTreeView.SelectedNode.Text.ToString()+".rpt");
                    fs.Write(b, 0, b.Length);
                    fs.Close();
                    C.Close();
                    return 0;
                catch (Exception ex)
                    MessageBox.Show(ex.Message);
                    return -1;
             * u0421u0442u0440u0443u043Au0442u0443u0440u0430, u043Eu043Fu0438u0441u044Bu0432u0430u044Eu0449u0430u044F u043Fu0430u0440u0430u043Cu0435u0442u0440u044B
             * u043Fu043Eu0434u043Au043Bu044Eu0447u0435u043Du0438u044F u043A u0431u0430u0437u0435 u0434u0430u043Du043Du044Bu0445,
             * u043Au0430u043A u0434u043Bu044F u0432u043Du0435u0448u043Du0435u0433u043E u0438u0441u043Fu043Eu043Bu044Cu0437u043Eu0432u0430u043Du0438u044F
             * u0442u0430u043A u0438 u0434u043Bu044F u0432u043Du0443u0442u0440u0435u043Du043Du0435u0433u043E
            public struct ConnectionString
                 * u0418u043Cu044F u0441u0435u0440u0432u0435u0440u0430 u0431u0430u0437u044B u0434u0430u043Du043Du044Bu0445
                private string DataSource_Value;
                 * u041Du0430u0437u0432u0430u043Du0438u0435 u0431u0430u0437u044B u0434u0430u043Du043Du044Bu0445
                private string InitialCatalog_Value;
                 * u0418u043Cu044F u043Fu043Eu043Bu044Cu0437u043Eu0432u0430u0442u0435u043Bu044F
                private string UserID_Value;
                 * u041Fu0430u0440u043Eu043Bu044C
                private string Password_Value;
                 * u041Fu0435u0440u0435u0433u0440u0443u0436u0435u043Du043Du044Bu0439 u043Au043Eu043Du0441u0442u0440u0443u043Au0442u043Eu0440
                 * u0434u043Bu044F u0440u0443u0447u043Du043Eu0439 u0438u043Du0438u0446u0438u0430u043Bu0438u0437u0430u0446u0438u0438
                 * u0441u0442u0440u043Eu043Au0438 u043Fu043Eu0434u043Au043Bu044Eu0447u0435u043Du0438u044F,
                 * u043Du0443u0436u0435u043D u0434u043Bu044F u0438u0441u043Fu043Eu043Bu044Cu0437u043Eu0432u0430u043Du0438u044F u0435u0433u043E
                 * u0432 u043Eu0434u0440u0443u0433u0438u0445 u0444u043Eu0440u043Cu0430u0445
                public ConnectionString(string /*
                                                * u0418u043Cu044F u0441u0435u0440u0432u0435u0440u0430 u0431u0430u0437u044B u0434u0430u043Du043Du044Bu0445
                                                  InDataSource_Value,
                                        string /*
                                                * u041Du0430u0437u0432u0430u043Du0438u0435 u0431u0430u0437u044B u0434u0430u043Du043Du044Bu0445
                                                  InInitialCatalog_Value,
                                        string /*
                                                * u0418u043Cu044F u043Fu043Eu043Bu044Cu0437u043Eu0432u0430u0442u0435u043Bu044F
                                                */ InUserID_Value,
                                        string /*
                                                * u041Fu0430u0440u043Eu043Bu044C
                                                */ InPassword_Value)
                    DataSource_Value = InDataSource_Value;
                    InitialCatalog_Value = InInitialCatalog_Value;
                    UserID_Value = InUserID_Value;
                    Password_Value = InPassword_Value;
                 * u041Fu043Eu043Bu0443u0447u0438u0442u044C u0438u043Cu044F u0441u0435u0440u0432u0435u0440u0430
                 * u0431u0430u0437u044B u0434u0430u043Du043Du044Bu0445
                public string GetServerName()
                    return DataSource_Value;
                 * u041Fu043Eu043Bu0443u0447u0438u0442u044C u043Du0430u0437u0432u0430u043Du0438u0435
                 * u0431u0430u0437u044B u0434u0430u043Du043Du044Bu0445
                public string GetDatabaseName()
                    return InitialCatalog_Value;
                 * u041Fu043Eu043Bu0443u0447u0438u0442u044C u0438u043Cu044F
                 * u0442u0435u043Au0443u0449u0435u0433u043E u043Fu043Eu043Bu044Cu0437u043Eu0432u0430u0442u0435u043Bu044F
                public string GetUserName()
                    return UserID_Value;
                 * u041Fu043Eu043Bu0443u0447u0438u0442u044C u043Fu0430u0440u043Eu043Bu044C
                 * u0442u0435u043Au0443u0449u0435u0433u043E u043Fu043Eu043Bu044Cu0437u043Eu0432u0430u0442u0435u043Bu044F
                public string GetPassword()
                    return Password_Value;
                 * u041Fu0435u0440u0435u0432u043Eu0434 u0441u0442u0440u0443u043Au0442u0443u0440u044B u0432 u0442u0435u043Au0441u0442u043Eu0432u044Bu0439 u0432u0438u0434
                 * u0434u043Bu044F u0438u0441u043Fu043Eu043Bu044Cu0437u043Eu0432u0430u043Du0438u044F u043Fu0440u0438 u0441u043Eu0437u0434u0430u043Du0438u0438 u043Au043Eu043Du043Du0435u043Au0442u043Eu0440u0430
                public override string ToString()
                    return "Data Source="+DataSource_Value+";Initial Catalog="+
                        InitialCatalog_Value+";User ID="+UserID_Value+";Password="+
                        Password_Value;
             * u0424u0443u043Du043Au0446u0438u044F u043Fu043Eu043Bu0443u0447u0435u043Du0438u044F u0441u0442u0440u043Eu043Au0438 u043Fu043Eu0434u043Au043Bu044Eu0447u0435u043Du0438u044F u043Fu043E u0443u043Cu043Eu043Bu0447u0430u043Du0438u044E
             * u043Du0443u0436u043Du0430 u0431u044Bu043Bu0430 u0434u043Bu044F u0442u0435u0441u0442u043Eu0432
            static private string GetDefaultConnectionString()
                return "Data Source=BSRV01;Initial Catalog=Prokat_Last;User ID=sa;Password=";
             * u0412u043Du0443u0442u0440u0435u043Du043Du044Fu044F u0441u0442u0440u043Eu043Au0430 u043Fu043Eu0434u043Au043Bu044Eu0447u0435u043Du0438u044F
             * u043Du0435 u0434u043Eu0441u0442u0443u043Fu043Du0430 u0434u043Bu044F u0432u044Bu0437u043Eu0432u0430 u043Du0430u043Fu0440u044Fu043Cu0443u044E
            private ConnectionString localConnectionString;
             * u0423u0441u0442u0430u043Du043Eu0432u0438u0442u044C u0441u0442u0440u043Eu043Au0443 u0432u043Du0443u0442u0440u0435u043Du043Du0435u0433u043E u043Fu043Eu0434u043Au043Bu044Eu0447u0435u043Du0438u044F
            public void SetConnectionString(ConnectionString CS)
                this.localConnectionString = CS;
             * u041Fu043Eu043Bu0443u0447u0438u0442u044C u0441u0442u0440u043Eu043Au0443 u0432u043Du0443u0442u0440u0435u043Du043Du0435u0433u043E u043Fu043Eu0434u043Au043Bu044Eu0447u0435u043Du0438u044F
            public ConnectionString GetConnectionString()
                return this.localConnectionString;
             * u0424u0443u043Du043Au0446u0438u044F u0443u0434u0430u043Bu0435u043Du0438u044F u0432u0440u0435u043Cu0435u043Du043Du043Eu0433u043E u0444u0430u0439u043Bu0430
             * u043Fu043Eu0441u043Bu0435 u0437u0430u0432u0435u0440u0448u0435u043Du0438u044F u0432u0441u0435u0445 u043Eu043Fu0435u0440u0430u0446u0438u0439 u0441 u0448u0430u0431u043Bu043Eu043Du043Eu043C
            private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
                if (FileTreeView.Nodes.Count!=0)
                    if (File.Exists(TemplateFilePath))
                        File.Delete(TemplateFilePath);
             * u041Eu0431u0440u0430u0431u043Eu0442u0447u0438u043A u0434u0432u043Eu0439u043Du043Eu0433u043E u043Au043Bu0438u043Au0430
             * u043Fu043E u0448u0430u0431u043Bu043Eu043Du0443 u0432 u0434u0435u0440u0435u0432u0435 u0444u0430u0439u043Bu043Eu0432
            public void FileTreeView_DoubleClick(object sender, EventArgs e)
                int Result = 0;
                try
                    Result = ParseReportWithDataBase();
                    if (Result == 0)
                        Result = ParseReport(TempFilePath + FileTreeView.SelectedNode.Text.ToString() + ".rpt");
                        if (Result == 0)
                            Process.Start(TemplateFilePath);
                    else
                        MessageBox.Show("u0424u0430u0439u043B u043Du0435 u043Cu043Eu0436u0435u0442 u0431u044Bu0442u044C u043Eu0442u043Au0440u044Bu0442!");
                catch (Exception ex)
                    MessageBox.Show(ex.Message);
             * u041Fu043Eu043Bu0443u0447u0435u043Du0438u0435 u0432u0441u0435u0445 u0444u0430u0439u043Bu043Eu0432 u0441 u0440u0430u0441u0448u0438u0440u0435u043Du0438u0435u043C .rpt
             * u0438u0437 u0431u0430u0437u044B u043A u043Au043Eu0442u043Eu0440u043Eu0439 u043Fu0440u0438u0441u043Eu0435u0434u0438u043Du0438u043Bu0438u0441u044C
            public void GetReportNamesFromDataBase(ConnectionString CS)
                try
                    SqlConnection C = new SqlConnection(CS.ToString());
                    SqlDataAdapter adapter = new SqlDataAdapter();
                    DataTable table = new DataTable();
                    table.Clear();
                    string sqlcom = "Select P115 from " + GetDataViewName(CS,"24") + " where P116 like '%.rpt'";
                    SqlCommand Q1 = new SqlCommand(sqlcom,C);
                    Q1.CommandType = CommandType.Text;
                    adapter.SelectCommand = Q1;
                    adapter.Fill(table);
                    FileTreeView.Nodes.Clear();
                    for (int i = 0; i < table.Rows.Count; i++)
                            FileTreeView.Nodes.Add(table.Rows<i>.ItemArray.GetValue(
                                table.Rows<i>.ItemArray.Length-1).ToString());
    //                        MessageBox.Show(table.Rows<i>.ItemArray.GetValue(0).ToString());
                    C.Close();
                catch (Exception ex)
                    MessageBox.Show(ex.Message);
             * u041Fu043Eu043Bu0443u0447u0438u0442u044C u0438u043Cu044F DataView
             * u0434u043Bu044F u0442u0435u043Au0443u0449u0435u0433u043E u043Fu043Eu043Bu044Cu0437u043Eu0432u0430u0442u0435u043Bu044F
            private string GetDataViewName(ConnectionString CS,string ClassID)
                string ViewName = "";
                SqlConnection C = new SqlConnection(CS.ToString());
                C.Open();
                SqlCommand Q = new SqlCommand("[dbo].[_SysGetClassesInfoNew1]"/*P115 from dbo.Attr24 where P116='.rpt'*/, C);
                Q.CommandType = CommandType.Text;
                SqlDataAdapter adapter = new SqlDataAdapter();
                adapter.SelectCommand = Q;
                DataTable table = new DataTable();
                adapter.Fill(table);
                for (int i = 0; i < table.Rows.Count; i++)
                    if (table.Rows<i>.ItemArray.GetValue(0).ToString() == ClassID)
                        ViewName = table.Rows<i>.ItemArray.GetValue(13).ToString();
                        // MessageBox.Show(ViewName);
                C.Close();
                return ViewName;
             * u041Eu0431u0440u0430u0431u043Eu0442u0447u0438u043A u043Au043Bu0438u043Au0430 u043Du0430 u0432u044Bu043Fu0430u0434u0430u044Eu0449u0435u043C
             * u043Cu0435u043Du044E u0432 u043Fu0443u043Du043Au0442u0435 "Delete"
            private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
                FileTreeView.SelectedNode.Remove();

  • ArrayList e .RangeCheck(int)line 546

    Hi guys I am working on this project
    in few word
    I have to draw different shape on a panel
    moreover when two similar shapes collide ( 2 circles ) they make a bigger circle
    when st change direction
    almost everything works
    import java.awt.Graphics;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.ArrayList;
    import java.util.Comparator;
    import java.util.Iterator;
    import javax.swing.JPanel;
    class ShapePanel extends JPanel implements ActionListener {
         private static final long serialVersionUID = 1L;
         public static ArrayList <Shape>shapes;
         private javax.swing.Timer animationTmr;
         int speed;
         PlaySound audioClip = new PlaySound();
         private float heigth;
         private float width;
         private int shape1;
         private int shape2;
         public ShapePanel() {
              shapes = new ArrayList<Shape>();
              animationTmr = new javax.swing.Timer(80, this); //interval, ActionListener
              animationTmr.start();
         public ArrayList<Shape> getShapes()
              return shapes;
         public void addSquare(int x, int y,int w,int h, int shapeType) {
              shapes.add(new Square(this,x, y,width, heigth, shapeType));
              repaint();
              System.out.println(shapes.size());
         public void addCircle(int x, int y,int w,int h, int shapeType) {
              shapes.add(new Circle(this, x, y,width, heigth, shapeType));
              repaint();
              System.out.println(shapes.size());
         public void addRectangle(int x, int y,int w,int h,  int shapeType) {
              shapes.add(new Rectangle(this, x, y,width, heigth, shapeType));
              repaint();
              System.out.println(shapes.size());
         public void addStar(int x, int y,int w,int h, int shapeType) {
              shapes.add(new Star(this, x, y,width, heigth, shapeType));
              repaint();
              System.out.println(shapes.size());
         public void paintComponent(Graphics g) { //called Whenever panel needs
              super.paintComponent(g); //re-displaying:
              Iterator<Shape> it = shapes.iterator(); //Iterate through Balls calling
              g.setColor(Menu.getColor());
              g.fillRect(0, 0, this.getWidth(), this.getHeight());
              while (it.hasNext()) { //each one's paint method
                   it.next().paint(g);
         public void actionPerformed(ActionEvent ev) {      
              //On timer tick,
              Iterator<Shape> it = shapes.iterator(); //Iterate through Balls calling
              while (it.hasNext()) { //each one's updatePos() method
                   it.next().updatePos();
              checkTypeCollision();
              handleCollision();
              repaint();
        private void checkTypeCollision()
              //we iterate through all the balls, checking for collision
              for(int i=0;i<shapes.size();i++)
                   for(int j=0;j<shapes.size();j++)
                             if(i!=j)
                                  if(collide(shapes.get(i), shapes.get(j)))
                                            shape1=shapes.get(i).shapeType;
                                            shape2=shapes.get(j).shapeType;
                                             if(shape1==shape2)
                                             /*     int     newX = (int) ((shapes.get(i).getCenterX() + (shapes.get(j).getCenterX()/2))/2);
                                                  int newY = (int) ((shapes.get(i).getCenterY() + (shapes.get(j).getCenterY() /2))/2);
                                                 float newWidth =   shapes.get(i).getWidth()+(shapes.get(j).getWidth()/2);
                                                 float newHeigth = shapes.get(i).getHeigth()+(shapes.get(j).getHeigth()/2);
                                                 int newShapeType = shapes.get(i).shapeType;
                                                       if(shapes.get(i).getShapeType()==1)
                                                            shapes.remove(j); //remove shape element at j
                                                            shapes.remove(i); //remove shape element at j
                                                            System.out.println("SIZE IS==="+     shapes.size());
                                                            System.out.println("newx====="+newX);
                                                            System.out.println("newy====="+newY);
                                                            System.out.println("newWidth====="+newWidth);
                                                            System.out.println("newx====="+newHeigth);
                                             //               shapes.add(new Rectangle(this,newX,newY,530,530,newShapeType));
                                                            System.out.println("SIZE IS==="+     shapes.size());
                                                       //     repaint();
                                                       if(shapes.get(i).getShapeType()==2)
                                                            shapes.remove(j); //remove shape element at j
                                                            shapes.remove(i); //remove shape element at j
                                                  //          shapes.add(new Circle(this,newX,newY,newWidth,newHeigth,newShapeType));
                                                       //     repaint();
                                                       if(shapes.get(i).getShapeType()==3)
                                                            shapes.remove(j); //remove shape element at j
                                                            shapes.remove(i); //remove shape element at j
                                                            shapes.add(new Square(this,newX,newY,newWidth,newHeigth,newShapeType));
                                                       if(shapes.get(i).getShapeType()==3)
                                                            shapes.remove(j); //remove shape element at j
                                                            shapes.remove(i); //remove shape element at j
                                                            //shapes.add(new Star(this,newX,newY,newWidth,newHeigth,newShapeType));
                                                       //     repaint();
         private void handleCollision()
              //we iterate through all the balls, checking for collision
              for(int i=0;i<shapes.size();i++)
                   for(int j=0;j<shapes.size();j++)
                             if(i!=j)
                                  if(collide(shapes.get(i), shapes.get(j)))
                                        shapes.get(i).hit(shapes.get(j));
                                       shapes.get(j).hit(shapes.get(i));                                   
         boolean collide(Shape b1, Shape b2)
              double wx=b1.getCenterX()-b2.getCenterX();
              double wy=b1.getCenterY()-b2.getCenterY();
              //we calculate the distance between the centers two
              //colliding balls (theorem of Pythagoras)
              double distance=Math.sqrt(wx*wx+wy*wy);
              if(distance<b1.shapeSize)     
                   audioClip.playRectangle();
                   return true;          
                   else return false;     
         public static int vectorSize()
              return shapes.size();
    }the drawing stops and
    i have this error after a while
    arrayList<e>.RangeCheck(int)line 546
    moreover it doesn t draw a bigger shape as i want with the line
    shapes.add(new Circle(this,newX,newY,newWidth,newHeigth,newShapeType));
                                                       help please the deadline is Tomorrow;

    Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Index: 4, Size: 4
         at java.util.ArrayList.RangeCheck(ArrayList.java:546)
         at java.util.ArrayList.get(ArrayList.java:321)
         at ShapePanel.checkTypeCollision(ShapePanel.java:156)
         at ShapePanel.actionPerformed(ShapePanel.java:77)
         at javax.swing.Timer.fireActionPerformed(Timer.java:271)
         at javax.swing.Timer$DoPostEvent.run(Timer.java:201)
         at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
         at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
    it doesn t compile because is part of a bigger project

  • How to get Int value from request.getParameter()?

    Hi all,
    I have a integer value which is passed from one page to another page.
    i am geting this value in the next page using
    request.getParameter().
    Eg.
    Suppose value of "i" in page1 is 32, i pass this as hidden variable to next page.
    <input type="hidden" Value="<%=i%>" NAME="limit">
    in page2, i fethch this value to a variable by name "limit"
    String limit=request.getParameter("limit");
    but, since value stored in limit is int, i can't assign it to string.
    i can't use request.getParameter for int values.
    How to solve my problem.
    I know it is simple,
    Pls. help me
    Regards
    ASh
    String limit=request.getParameter("limit");

      String limitSTR = request.getParameter("limit");
      int limit = -1;
      if (limitSTR != null) limit = Integer.parseInt(limitSTR);

  • How can I convert an int to a string?

    Hi
    How can I convert an int to a string?
    /ad87geao

    Here is some the code:
    public class GUI
        extends Applet {
      public GUI() { 
        lastValue = 5;
        String temp = Integer.toString(lastValue);
        System.out.println(temp);
        showText(temp);
      private void showText(final String text) {
        SwingUtilities.invokeLater(new Runnable() {
          public void run() {
            tArea2.setText(text + "\n");
    }

  • Fields appear as "Read Only" in an Int.Form called from a WD

    Hi Experts!
    I am having a doubt in an Adobe Int.Form, that is called from a WD application.
    The fields that are in my Form, always appear as a "read only". It is not possible to modify anything there.
    Here, I describe the steps that I follow.
    I create a very simple WD application. In its WD View, exist an unique Object (Adobe Interactive Form).
    In that object, I set the properties:
    "Data source": a context variable type "my structure". "My structure", is a simple structure with a couple or three fields, let´s say PERNR, BUKRS, WERKS... It is linked to the Form Interface (ABAP DICTIONARY-BASED INTERFACE). So in this way, the link between my WD and the AdobeInt.Form is working.
    "PDF Source": a context variable type XSTRING.
    "Template Source": here I have set my Int.Form. Currently, it only contains a couple of fields
    "Enabled": True.
    "Read Only": False.
    In the AdobeForm, I have drag & droped those 2 or 3 fields, save it, and activate it. I guess nothing more is needed, for my test.
    And at last, in the View´s method WDDOINIT, I am reading one of those fields, let´s say the employee number (PERNR), and I set by hardcoding its number (let´s say -> 00000001).
    Until here, everything seems to work fine. When I launch the WD test, the Adobeform appears, at the moment, with only one of my fields (Employee - PERNR), and its value is filled in with '00000001'.
    But now, I would like to write something by myself. And when I try to do it, it is not possible! Field PERNR, is displayed as a "READ ONLY".
    Someone knows what is happening here? I guess it should be possible, to activate as a "EDITABLE" that field in my Form.
    So here is my doubt.
    Am I doing anything wrong? Or am I doing any mistake?
    Thank you very much in advance!

    Finally I think I have found the problem.
    In the View where I am printing the ADOBEFORM, it is needed this code under the method WDDOMODIFYVIEW.
    method WDDOMODIFYVIEW .
      DATA: LV_INTERACTIVE_FORM   TYPE REF TO CL_WD_INTERACTIVE_FORM,
                 LV_METHOD_HANDLER     TYPE REF TO IF_WD_IACTIVE_FORM_METHOD_HNDL.
      LV_INTERACTIVE_FORM ?= VIEW->GET_ELEMENT( 'INT_FORM' ). "   adobeform object in view
      IF LV_INTERACTIVE_FORM IS NOT INITIAL.
          LV_METHOD_HANDLER ?= LV_INTERACTIVE_FORM->_METHOD_HANDLER.
          LV_METHOD_HANDLER->SET_LEGACY_EDITING_ENABLED( ABAP_TRUE ).
          LV_METHOD_HANDLER->SET_HIDE_NAVIGATION_PANEL( ABAP_TRUE ).
          LV_METHOD_HANDLER->SET_DISABLE_PRINT_BUTTON( ABAP_TRUE ).
          WD_THIS->M_METHOD_HANDLER ?= LV_INTERACTIVE_FORM->_METHOD_HANDLER.
          WD_THIS->M_METHOD_HANDLER->SET_HIDE_TOOLBARS( ABAP_TRUE ).
        ENDIF.
    endmethod.
    Regards,
    Carles

  • Can not cast from object to int

    Hi All,
    I have the following bunch of code
    Session session;
              session = getSessionFactory().openSession();
              Query query;
              int MaxPageId = 0;
              List list;
              try{
                   query = session.createQuery("select max(emp.id) from EmpBean emp");
                   list = query.list();
                   MaxPageId = (int) list.get(0);
                   return MaxPageId;
              catch(Exception e){
                   System.out.println(e.getMessage());
              return MaxPageId;
    The query executed successfully but when i get the max id in a integer variable by the following statement
    MaxPageId = (int) list.get(0);
    I get the following error "can not cast from object to int"
    Please suggest for the same.
    -Thanks

    Cast to an Integer, not an int, and let autoboxing turn the Integer into an int.
    int maxPageId;
    maxPageId = (Integer) list.get(0);You can't cast objects into primitives.
    Autoboxing isn't casting.
    And use Java naming conventions. Local variables start with a lower-case letter.

  • Returning int array from C to Java as method parameter

    Hello,
    I've been trying to accomplish this
    Java
    int[] myArray = ... (filled with some data);
    int retCode = myNativeCall(myArray);
    if(retCode == 0)
    doSomethingWith(myArray); //myArray gets overwritten with new data (with new size also) during the native call...
    C
    JNIEXPORT jint JNICALL Java_GenChav_rsaEncrypt(JNIEnv *env, jobject obj, jintArray myArray){
    jintArray outbuf;
    int[] new_array = .. // some function will fill this....
    int new_array_length = ...//some function will give me the new size, not big, 512 max...
    jint tmp[new_array_length]; //allocate..need something more ??
    memcpy(tmp, new_array, new_array_lenght);
    outbuf=(*env)->NewIntArray(env, new_array_length);
    (*env)->SetIntArrayRegion(env, outbuf, 0, new_array_length, tmp);
    myArray=outbuf;
    I tought this way I would have a updated myArray ints on the Java program...
    Any thought??

    user5945780 wrote:
    Ok, let's try to be constructive here...
    How I do implement a return type for my method like a int array ?First realized it has nothing to do with JNI. So the same question and answer applies to java only.
    >
    like:
    int[] return = myNativeCall();
    Yes.
    Then I will look for return[0], if it is == to 0, fine, it means a successful calculation by the native code. Not sure what that means. The structure of what you return it up to you.
    It can help when you are unsure of what to do in JNI....write a pseudo representation of what you want to do in a java method. Then translate that java method into JNI, everything in the pseudo method must be in the JNI code.

  • SocketInputStream.read(byte[], int, int) extremely slow

    Hi everyone,
    I'm trying to send several commands to a server and for each command read one or more lines as response. To do that I'm using a good old Socket connection. I'm reading the response lines with BufferedReader.readLine, but it's very slow. VisualVM says, that SocketInputStream.read(byte[], int, int) is consuming most of the cpu time. A perl script, which does the same job, finishes in no time. So it's not a problem with the server.
    I'm runnning java version "1.6.0_12"
    Java(TM) SE Runtime Environment (build 1.6.0_12-b04)
    Java HotSpot(TM) Server VM (build 11.2-b01, mixed mode) on Linux henni 2.6.25-gentoo-r7 #3 SMP PREEMPT Sat Jul 26 19:35:54 CEST 2008 i686 Intel(R) Core(TM)2 Duo CPU E6550 @ 2.33GHz GenuineIntel GNU/Linux and here's my code
    private List<Response> readResponse() throws IOException {
            List<Response> responses = new ArrayList<Response>();
            String line = "";
            while ( (line = in.readLine()) != null) {
                int code = -1;
                try {
                    code = Integer.parseInt(line.substring(0, 3));
                    line = line.substring(4);
                } catch (Exception e) {
                    code = -1;
                // TODO create different response objects ?!?
                NotImplemented res = new NotImplemented(code, line);
                responses.add(res);
                // we received an "end of response" line and can stop reading from the socket
                if(code >= 200 && code < 300) {
                    break;
            return responses;
        }Any hints are appreciated.
    Best regards,
    Henrik

    Though it's almost an sscce I posted there, I will try to shrink it a little bit:
    Dummy server:
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.PrintStream;
    import java.net.ServerSocket;
    import java.net.Socket;
    public class Server {
        public Server() throws IOException {
            ServerSocket ss = new ServerSocket(2011);
            Socket sock = ss.accept();
            BufferedReader br = new BufferedReader(new InputStreamReader(sock.getInputStream()));
            PrintStream ps = new PrintStream(sock.getOutputStream());
            ps.println("200 Welcome on the dummy server");
            String line = "";
            while(line != null) {
                line = br.readLine();
                ps.println("200 Ready.");
        public static void main(String[] args) throws IOException {
            new Server();
    }the client:
    import java.io.IOException;
    import java.io.PrintStream;
    import java.net.InetSocketAddress;
    import java.net.Socket;
    import java.net.UnknownHostException;
    import java.util.Scanner;
    import de.berlios.vch.Config;
    public class Client {
        private Socket socket;
        private PrintStream out;
        private Scanner scanner;
        public Client(String host, int port, int timeout, String encoding)
            throws UnknownHostException, IOException {
            socket = new Socket();
            InetSocketAddress sa = new InetSocketAddress(host, port);
            socket.connect(sa, timeout);
            out = new PrintStream(socket.getOutputStream(), true, encoding);
            scanner = new Scanner(socket.getInputStream(), encoding);
        public synchronized void send(String cmd) throws IOException {
            // send command to server
            out.println(cmd);
            // read response lines
            readResponse();
        public void readResponse() throws IOException {
            while (scanner.hasNextLine()) {
                String line = scanner.nextLine();
                System.out.println(line);
                int code = -1;
                try {
                    code = Integer.parseInt(line.substring(0, 3));
                    line = line.substring(4);
                } catch (Exception e) {
                    code = -1;
                if (code >= 200 && code < 300) {
                    break;
        public static void main(String[] args) {
            try {
                Client con = new Client("localhost", 2011, 500, "utf-8");
                con.readResponse();
                con.send("version 0.1");
                con.send("menu = new menu Feeds");
                con.send("menu.EnableEvent close");
                con.send("menu.SetColorKeyText -red 'Öffnen'");
                for (int i = 0; i < 100; i++) {
                    String groupId = "group"+i;
                    long start = System.currentTimeMillis();
                    con.send(groupId+" = menu.AddNew OsdItem '"+groupId+"'");
                    con.send(groupId+".EnableEvent keyOk keyRed");
                    long stop = System.currentTimeMillis();
                    System.out.println((stop-start)+"ms");
            } catch (Exception e) {
                e.printStackTrace();
    }This code makes me believe, it's not a java problem, but some system setting of my os.

  • Class & int/String issues

    Upon compiling, I am receiving the following errors:
    TeamRosterApp.java:153: cannot find symbol
    symbol : class ButtonPanel
    location: class TeamRosterPanel
    ButtonPanel buttonPanel;
    ^
    TeamRosterApp.java:166: cannot find symbol
    symbol : class ButtonPanel
    location: class TeamRosterPanel
    buttonPanel = new ButtonPanel();
    ^
    2 errors
    I've included the code below, but I having difficulty understanding why it cannot find the ButtonPanel class when that class is specified in the code (Line 364).
    Thanks in advance for your help!
    //Modified by Doe, John 20OCT2007
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.text.JTextComponent;
    import java.util.ArrayList;
    import java.text.*;
    import java.lang.*;
    import java.util.*;
    public class TeamRosterApp
         public static void main(String[] args)
              TeamIO.getTeam();
                    JFrame frame = new TeamRosterFrame();
                    frame.setVisible(true);
    class Player
         String lname;
         String fname;
         int number;
         public Player()
              lname = "";
              fname = "";
              number = 0;
         public Player(String lname, String fname, int number)
              this.lname = lname;
              this.fname = fname;
              this.number = number;
         public void setLastName(String lname)
              this.lname = lname;
         public String getLastName()
              return lname;
         public void setFirstName(String fname)
              this.fname = fname;
         public String getFirstName()
              return fname;
         public void setNumber(int number)
              this.number = number;
         public int getNumber()
              return number;
    class TeamIO
         private static final ArrayList<Player> team = new ArrayList<Player>();
         public static ArrayList<Player> getTeam()
              team.add(new Player("Doe", "John", 69));
              team.add(new Player("Berg", "Laura", 44));
              team.add(new Player("Bustos", "Crystl", 6));
              team.add(new Player("Clark", "Jamie", 24));
              team.add(new Player("Fernandez", "Lisa", 16));
              team.add(new Player("Finch", "Jennie", 27));
              team.add(new Player("Flowers", "Tairia", 11));
              team.add(new Player("Freed", "Amanda", 7));
              team.add(new Player("Giordano", "Nicole", 4));
              team.add(new Player("Harrigan", "Lori", 21));
              team.add(new Player("Jung", "Lovieanne", 3));
              team.add(new Player("Kretchman", "Kelly", 12));
              team.add(new Player("Lappin", "Lauren", 37));
              team.add(new Player("Mendoza", "Jessica", 2));
              team.add(new Player("O'Brien-Amico", "Lisa", 20));
              team.add(new Player("Nuveman", "Stacy", 33));
              team.add(new Player("Osterman", "Catherine", 8));
              team.add(new Player("Topping", "Jennie", 31));
              team.add(new Player("Watley", "Natasha", 29));
              System.out.println("\nOpening team list" + "\n\n" + "****************************************");
              for(int i = 0; i < team.size(); i++)
                   Player p = (Player)team.get(i);
                   System.out.print(p.getNumber() + "\t" + p.getLastName() + "," + p.getFirstName() + "\n");
                   System.out.println("****************************************");
              return new ArrayList<Player>(team);
         public static ArrayList<Player> saveTeam()
              System.out.println("\nOpening team list" + "\n\n" + "****************************************");
              for(int i = 0; i < team.size(); i++)
              Player p = (Player)team.get(i);
              System.out.print(p.getNumber() + "\t" + p.getLastName() + "," + p.getFirstName() + "\n");
              System.out.println("****************************************");
              return new ArrayList<Player>(team);
    class TeamRosterFrame extends JFrame
        public TeamRosterFrame()
            String me = "Campbell, Corey";
              String date;
              Date now = new Date();
              DateFormat longDate = DateFormat.getDateInstance(DateFormat.LONG);
              date = longDate.format(now);
              setTitle("Team Roster "+me+" "+date);
            setResizable(false);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            this.add(new TeamRosterPanel());
            this.pack();
            centerWindow(this);
        private void centerWindow(Window w)
            Toolkit tk = Toolkit.getDefaultToolkit();
            Dimension d = tk.getScreenSize();
            setLocation((d.width-w.getWidth())/2, (d.height-w.getHeight())/2);
    class TeamRosterPanel extends JPanel
         ArrayList<Player>team;
         Player newPlayer = null;
         teamSelectorPanel selectorPanel;
         PlayerDisplayPanel playerPanel;
         ButtonPanel buttonPanel;
         public TeamRosterPanel()
              // fill the team ArrayList
              team = TeamIO.getTeam();
              // add the panels
              setLayout(new GridBagLayout());
              selectorPanel = new teamSelectorPanel();
              add(selectorPanel, getConstraints(0,0,1,1, GridBagConstraints.WEST));
              playerPanel = new PlayerDisplayPanel();
              add(playerPanel, getConstraints(0,1,1,1, GridBagConstraints.EAST));
              buttonPanel = new ButtonPanel();
              add(buttonPanel, getConstraints(0,2,1,1, GridBagConstraints.EAST));
              // set the initial player to be displayed
              playerPanel.showPlayer(team.get(0));
              selectorPanel.selectPlayer(team.get(0));
         // a method for setting grid bag constraints
         private GridBagConstraints getConstraints(int gridx, int gridy,
              int gridwidth, int gridheight, int anchor)
              GridBagConstraints c = new GridBagConstraints();
              c.insets = new Insets(5, 5, 5, 5);
              c.ipadx = 0;
              c.ipady = 0;
              c.gridx = gridx;
              c.gridy = gridy;
              c.gridwidth = gridwidth;
              c.gridheight = gridheight;
              c.anchor = anchor;
              return c;
         class teamSelectorPanel extends JPanel implements ActionListener
              public JComboBox    playerComboBox;
              private JLabel      playerLabel;
              boolean filling = false;            // used to indicate the combo box is being filled
              public teamSelectorPanel()
                   // set panel layout
                   setLayout(new FlowLayout(FlowLayout.LEFT));
                   // Player label
                   playerLabel = new JLabel("Select Player:");
                   add(playerLabel);
                   // Player combo box
                   playerComboBox = new JComboBox();
                   fillComboBox(team);
                   playerComboBox.addActionListener(this);
                   add(playerComboBox);
              public void actionPerformed(ActionEvent e)
                   if (!filling)
                        Player p = (Player)playerComboBox.getSelectedItem();
                        playerPanel.showPlayer(p);
              public void fillComboBox(ArrayList<Player> team)
              filling = true;
              playerComboBox.removeAllItems();
              for (Player p : team)
              playerComboBox.addItem(p);
              filling = false;
              public void selectPlayer(Player p)
                   playerComboBox.setSelectedItem(p);
              public Player getCurrentPlayer()
                   return (Player) playerComboBox.getSelectedItem();
         class PlayerDisplayPanel extends JPanel
              public JTextField   lastNameTextField,
                   firstNameTextField,
                   numberTextField;
              private JLabel      lastNameLabel,
                   firstNameLabel,
                   numberLabel;
              public PlayerDisplayPanel()
                   // set panel layout
                   setLayout(new GridBagLayout());
                   // last name label
                   lastNameLabel = new JLabel("Last name:");
                   add(lastNameLabel, getConstraints(0,0,1,1, GridBagConstraints.EAST));
                   // last name text field
                   lastNameTextField = new JTextField(10);
                   lastNameTextField.setEditable(false);
                   lastNameTextField.setFocusable(false);
                   lastNameTextField.addFocusListener(new AutoSelect());
                   add(lastNameTextField, getConstraints(1,0,1,1, GridBagConstraints.WEST));
                   // first name label
                   firstNameLabel = new JLabel("First name:");
                   add(firstNameLabel, getConstraints(0,1,1,1, GridBagConstraints.EAST));
                   // first name text field
                   firstNameTextField = new JTextField(30);
                   firstNameTextField.setEditable(false);
                   firstNameTextField.setFocusable(false);
                   firstNameTextField.addFocusListener(new AutoSelect());
                   add(firstNameTextField, getConstraints(1,1,1,1, GridBagConstraints.WEST));
                   // number label
                   numberLabel = new JLabel("Number:");
                   add(numberLabel, getConstraints(0,2,1,1, GridBagConstraints.EAST));
                   // number text field
                   numberTextField = new JTextField(10);
                   numberTextField.setEditable(false);
                   numberTextField.setFocusable(false);
                   numberTextField.addFocusListener(new AutoSelect());
                   numberTextField.addKeyListener(new IntFilter());
                   add(numberTextField, getConstraints(1,2,1,1, GridBagConstraints.WEST));
              public void showPlayer(Player p)
                   lastNameTextField.setText(p.getLastName());
                   firstNameTextField.setText(p.getFirstName());
                   numberTextField.setText(String.valueOf(p.getNumber()));
              public void clearFields()
                   lastNameTextField.setText("");
                   firstNameTextField.setText("");
                   numberTextField.setText("");
              // return a new Player object with the data in the text fields
              public Player getPlayer()
                   Player p = new Player();
                   p.setLastName(lastNameTextField.getText());
                   p.setFirstName(firstNameTextField.getText());
                   int n = Integer.parseInt(numberTextField.getText());
                   p.setNumber(n);
                   return p;
              public void setAddEditMode(boolean e)
                   lastNameTextField.setEditable(e);
                   lastNameTextField.setFocusable(e);
                   lastNameTextField.requestFocusInWindow();
                   firstNameTextField.setEditable(e);
                   firstNameTextField.setFocusable(e);
                   numberTextField.setEditable(e);
                   numberTextField.setFocusable(e);
              class AutoSelect implements FocusListener
                   public void focusGained(FocusEvent e)
                        if(e.getComponent() instanceof JTextField)
                             JTextField t = (JTextField) e.getComponent();
                             t.selectAll();
                   public void focusLost(FocusEvent e){}
              class IntFilter implements KeyListener
                   public void keyTyped(KeyEvent e)
                        char c = e.getKeyChar();
                        if ( c !='0' && c !='1' && c !='2' && c !='3' && c !='4' && c !='5'
                             && c !='6' && c !='7' && c !='8' && c !='9')
                             e.consume();
                   public void keyPressed(KeyEvent e){}
                   public void keyReleased(KeyEvent e){}
              class ButtonPanel extends JPanel
                   public JButton addButton,
                        editButton,
                        deleteButton,
                        acceptButton,
                        cancelButton,
                        exitButton;
                   public ButtonPanel()
                        // create maintenance button panel
                        JPanel maintPanel = new JPanel();
                        maintPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
                        // add button
                        addButton = new JButton("Add");
                        addButton.addActionListener(new AddListener());
                        maintPanel.add(addButton);
                        // edit button
                        editButton = new JButton("Edit");
                        editButton.addActionListener(new EditListener());
                        maintPanel.add(editButton);
                        // delete button
                        deleteButton = new JButton("Delete");
                        deleteButton.addActionListener(new DeleteListener());
                        maintPanel.add(deleteButton);
                        // accept button
                        acceptButton = new JButton("Accept");
                        acceptButton.setEnabled(false);
                        acceptButton.addActionListener(new AcceptListener());
                        maintPanel.add(acceptButton);
                        // cancel button
                        cancelButton = new JButton("Cancel");
                        cancelButton.setEnabled(false);
                        cancelButton.addActionListener(new CancelListener());
                        maintPanel.add(cancelButton);
                        // create exit button panel
                        JPanel exitPanel = new JPanel();
                        exitPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
                        // exit button
                        exitButton = new JButton("Exit");
                        exitButton.addActionListener(new ExitListener());
                        exitPanel.add(exitButton);
                        // add panels to the ButtonPanel
                        setLayout(new BorderLayout());
                        add(maintPanel, BorderLayout.CENTER);
                        add(exitPanel, BorderLayout.SOUTH);
                   public void setAddEditMode(boolean e)
                        addButton.setEnabled(!e);
                        editButton.setEnabled(!e);
                        deleteButton.setEnabled(!e);
                        acceptButton.setEnabled(e);
                        cancelButton.setEnabled(e);
              class AddListener implements ActionListener
                   public void actionPerformed(ActionEvent e)
                        newPlayer = new Player();
                        playerPanel.clearFields();
                        buttonPanel.setAddEditMode(true);
                        playerPanel.setAddEditMode(true);
              class EditListener implements ActionListener
                   public void actionPerformed(ActionEvent e)
                        buttonPanel.setAddEditMode(true);
                        playerPanel.setAddEditMode(true);
              class DeleteListener implements ActionListener
                   public void actionPerformed(ActionEvent e)
                        Player p = selectorPanel.getCurrentPlayer();
                        team.remove(p);
                        TeamIO.saveTeam();
                        selectorPanel.fillComboBox(team);
                        selectorPanel.selectPlayer(team.get(0));
                        playerPanel.showPlayer(team.get(0));
                        selectorPanel.playerComboBox.requestFocusInWindow();
              class AcceptListener implements ActionListener
                   public void actionPerformed(ActionEvent e)
                        if (isValidData())
                             if (newPlayer != null)
                                  newPlayer = playerPanel.getPlayer();
                                  team.add(newPlayer);
                                  TeamIO.saveTeam();
                                  selectorPanel.fillComboBox(team);
                                  selectorPanel.selectPlayer(newPlayer);
                                  newPlayer = null;
                             else
                                  Player p = selectorPanel.getCurrentPlayer();
                                  Player newPlayer = playerPanel.getPlayer();
                                  p.setLastName(newPlayer.getLastName());
                                  p.setFirstName(newPlayer.getFirstName());
                                  p.setNumber(newPlayer.getNumber());
                                  TeamIO.saveTeam();
                                  selectorPanel.fillComboBox(team);
                                  selectorPanel.selectPlayer(p);
                                  playerPanel.showPlayer(selectorPanel.getCurrentPlayer());
                             playerPanel.setAddEditMode(false);
                             buttonPanel.setAddEditMode(false);
                             selectorPanel.playerComboBox.requestFocusInWindow();
                   public boolean isValidData()
                        return SwingValidator.isPresent(playerPanel.lastNameTextField, "Last Name")
                             && SwingValidator.isPresent(playerPanel.firstNameTextField, "First Name")
                             && SwingValidator.isPresent(playerPanel.numberTextField, "Number")
                             && SwingValidator.isInteger(playerPanel.numberTextField, "Number");
              class CancelListener implements ActionListener
                   public void actionPerformed(ActionEvent e)
                        if (newPlayer != null)
                             newPlayer = null;
                        playerPanel.setAddEditMode(false);
                        playerPanel.showPlayer(selectorPanel.getCurrentPlayer());
                        buttonPanel.setAddEditMode(false);
                        selectorPanel.playerComboBox.requestFocusInWindow();
              class ExitListener implements ActionListener
                   public void actionPerformed(ActionEvent e)
                        System.exit(0);
    }Swing Validator Code:
    //Programmed by Doe, John 20OCT2007
    import javax.swing.*;
    import javax.swing.text.JTextComponent;
    public class SwingValidator
         public static boolean isPresent(JTextComponent c, String title)
              if(c.getText().length()==0)
                   showMessage(c, title + " is a required field.\n" + "Please re-enter.");
                   c.requestFocusInWindow();
                   return false;
              return true;
         public static boolean isInteger(JTextComponent c, String title)
              try
                   int i = Integer.parseInt(c.getText());
                   return true;
              catch(NumberFormatException e)
                   showMessage(c,title+" must be an integer.\n"+"Please re-enter.");
                   c.requestFocusInWindow();
                   return false;
         private static void showMessage(JTextComponent c, String message)
              JOptionPane.showMessageDialog(c, message, "Invalid Entry", JOptionPane.ERROR_MESSAGE);
    }Edited by: kc0poc on Oct 21, 2007 8:17 AM

    Ok. Got it, understand it now. Corrected all 58 errors after created the top level classes. It compiles, but I'm now encountering a NullPointerException:
    Exception in thread "main" java.lang.NullPointerException
    at teamSelectorPanel.fillComboBox(TeamRosterAppTest.java:233)
    at teamSelectorPanel.<init>(TeamRosterAppTest.java:214)
    at TeamRosterPanel.<init>(TeamRosterAppTest.java:164)
    at TeamRosterFrame.<init>(TeamRosterAppTest.java:135)
    at TeamRosterAppTest.main(TeamRosterAppTest.java:17)
    I think I am not initializing something correctly and it involved the "team" variable. Thoughts anyone?
    Thank you as always!
    Below is my code:
    //Modified by Campbell, Corey 20OCT2007
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.text.JTextComponent;
    import java.util.ArrayList;
    import java.text.*;
    import java.lang.*;
    import java.util.*;
    public class TeamRosterAppTest
         public static void main(String[] args)
              TeamIO.getTeam();
              JFrame frame = new TeamRosterFrame();
              frame.setVisible(true);
    class Player
         String lname;
         String fname;
         int number;
         public Player()
              lname = "";
              fname = "";
              number = 0;
         public Player(String lname, String fname, int number)
              this.lname = lname;
              this.fname = fname;
              this.number = number;
         public void setLastName(String lname)
              this.lname = lname;
         public String getLastName()
              return lname;
         public void setFirstName(String fname)
              this.fname = fname;
         public String getFirstName()
              return fname;
         public void setNumber(int number)
              this.number = number;
         public int getNumber()
              return number;
    class TeamIO
         private static final ArrayList<Player> team = new ArrayList<Player>();
         public static ArrayList<Player> getTeam()
              team.add(new Player("Campbell", "Corey", 69));
              team.add(new Player("Berg", "Laura", 44));
              team.add(new Player("Bustos", "Crystl", 6));
              team.add(new Player("Clark", "Jamie", 24));
              team.add(new Player("Fernandez", "Lisa", 16));
              team.add(new Player("Finch", "Jennie", 27));
              team.add(new Player("Flowers", "Tairia", 11));
              team.add(new Player("Freed", "Amanda", 7));
              team.add(new Player("Giordano", "Nicole", 4));
              team.add(new Player("Harrigan", "Lori", 21));
              team.add(new Player("Jung", "Lovieanne", 3));
              team.add(new Player("Kretchman", "Kelly", 12));
              team.add(new Player("Lappin", "Lauren", 37));
              team.add(new Player("Mendoza", "Jessica", 2));
              team.add(new Player("O'Brien-Amico", "Lisa", 20));
              team.add(new Player("Nuveman", "Stacy", 33));
              team.add(new Player("Osterman", "Catherine", 8));
              team.add(new Player("Topping", "Jennie", 31));
              team.add(new Player("Watley", "Natasha", 29));
              //System.out.println("\nOpening team list" + "\n\n" + "****************************************");
              //for(int i = 0; i < team.size(); i++)
              //          Player p = (Player)team.get(i);
              //          System.out.print(p.getNumber() + "\t" + p.getLastName() + "," + p.getFirstName() + "\n");
              //System.out.println("****************************************");
              return new ArrayList<Player>(team);
         public static ArrayList<Player> saveTeam()
              System.out.println("\nOpening team list" + "\n\n" + "****************************************");
              for(int i = 0; i < team.size(); i++)
                   Player p = (Player)team.get(i);
                   System.out.print(p.getNumber() + "\t" + p.getLastName() + "," + p.getFirstName() + "\n");
              System.out.println("****************************************");
              return new ArrayList<Player>(team);
    class TeamRosterFrame extends JFrame
         public TeamRosterFrame()
              String me = "Campbell, Corey";
              String date;
              Date now = new Date();
              DateFormat longDate = DateFormat.getDateInstance(DateFormat.LONG);
              date = longDate.format(now);
              setTitle("Team Roster "+me+" "+date);
              setResizable(false);
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              this.add(new TeamRosterPanel());
              this.pack();
              centerWindow(this);
         private void centerWindow(Window w)
              Toolkit tk = Toolkit.getDefaultToolkit();
              Dimension d = tk.getScreenSize();
              setLocation((d.width-w.getWidth())/2, (d.height-w.getHeight())/2);
    class TeamRosterPanel extends JPanel
         ArrayList<Player>team;
         Player newPlayer = null;
         teamSelectorPanel selectorPanel;
         PlayerDisplayPanel playerPanel;
         ButtonPanel buttonPanel;
         public TeamRosterPanel()
              // fill the team ArrayList
              team = TeamIO.getTeam();
              // add the panels
              setLayout(new GridBagLayout());
              selectorPanel = new teamSelectorPanel();
              add(selectorPanel, getConstraints(0,0,1,1, GridBagConstraints.WEST));
              playerPanel = new PlayerDisplayPanel();
              add(playerPanel, getConstraints(0,1,1,1, GridBagConstraints.EAST));
              buttonPanel = new ButtonPanel();
              add(buttonPanel, getConstraints(0,2,1,1, GridBagConstraints.EAST));
              // set the initial player to be displayed
              playerPanel.showPlayer(team.get(0));
              selectorPanel.selectPlayer(team.get(0));
         // a method for setting grid bag constraints
         private GridBagConstraints getConstraints(int gridx, int gridy,
              int gridwidth, int gridheight, int anchor)
              GridBagConstraints c = new GridBagConstraints();
              c.insets = new Insets(5, 5, 5, 5);
              c.ipadx = 0;
              c.ipady = 0;
              c.gridx = gridx;
              c.gridy = gridy;
              c.gridwidth = gridwidth;
              c.gridheight = gridheight;
              c.anchor = anchor;
              return c;
    class teamSelectorPanel extends JPanel implements ActionListener
         public JComboBox playerComboBox;
         private JLabel playerLabel;
         boolean filling = false;            // used to indicate the combo box is being filled
         ArrayList<Player>team;
         PlayerDisplayPanel playerPanel;
         public teamSelectorPanel()
              // set panel layout
              setLayout(new FlowLayout(FlowLayout.LEFT));
              // Player label
              playerLabel = new JLabel("Select Player:");
              add(playerLabel);
              // Player combo box
              playerComboBox = new JComboBox();
              fillComboBox(team);
              playerComboBox.addActionListener(this);
              add(playerComboBox);
         public void actionPerformed(ActionEvent e)
              if (!filling)
                   Player p = (Player)playerComboBox.getSelectedItem();
                   playerPanel.showPlayer(p);
         public void fillComboBox(ArrayList<Player> team)
              filling = true;
              playerComboBox.removeAllItems();
              for (Player p : team)
              playerComboBox.addItem(p);
              filling = false;
         public void selectPlayer(Player p)
              playerComboBox.setSelectedItem(p);
         public Player getCurrentPlayer()
              return (Player) playerComboBox.getSelectedItem();
    class PlayerDisplayPanel extends JPanel
         public JTextField lastNameTextField,
              firstNameTextField,
              numberTextField;
         private JLabel lastNameLabel,
              firstNameLabel,
              numberLabel;
         public PlayerDisplayPanel()
              // set panel layout
              setLayout(new GridBagLayout());
              // last name label
              lastNameLabel = new JLabel("Last name:");
              add(lastNameLabel, getConstraints(0,0,1,1, GridBagConstraints.EAST));
              // last name text field
              lastNameTextField = new JTextField(10);
              lastNameTextField.setEditable(false);
              lastNameTextField.setFocusable(false);
              lastNameTextField.addFocusListener(new AutoSelect());
              add(lastNameTextField, getConstraints(1,0,1,1, GridBagConstraints.WEST));
              // first name label
              firstNameLabel = new JLabel("First name:");
              add(firstNameLabel, getConstraints(0,1,1,1, GridBagConstraints.EAST));
              // first name text field
              firstNameTextField = new JTextField(30);
              firstNameTextField.setEditable(false);
              firstNameTextField.setFocusable(false);
              firstNameTextField.addFocusListener(new AutoSelect());
              add(firstNameTextField, getConstraints(1,1,1,1, GridBagConstraints.WEST));
              // number label
              numberLabel = new JLabel("Number:");
              add(numberLabel, getConstraints(0,2,1,1, GridBagConstraints.EAST));
              // number text field
              numberTextField = new JTextField(10);
              numberTextField.setEditable(false);
              numberTextField.setFocusable(false);
              numberTextField.addFocusListener(new AutoSelect());
              numberTextField.addKeyListener(new IntFilter());
              add(numberTextField, getConstraints(1,2,1,1, GridBagConstraints.WEST));
         public void showPlayer(Player p)
              lastNameTextField.setText(p.getLastName());
              firstNameTextField.setText(p.getFirstName());
              numberTextField.setText(String.valueOf(p.getNumber()));
         public void clearFields()
              lastNameTextField.setText("");
              firstNameTextField.setText("");
              numberTextField.setText("");
         // return a new Player object with the data in the text fields
         public Player getPlayer()
              Player p = new Player();
              p.setLastName(lastNameTextField.getText());
              p.setFirstName(firstNameTextField.getText());
              int n = Integer.parseInt(numberTextField.getText());
              p.setNumber(n);
              return p;
         public void setAddEditMode(boolean e)
              lastNameTextField.setEditable(e);
              lastNameTextField.setFocusable(e);
              lastNameTextField.requestFocusInWindow();
              firstNameTextField.setEditable(e);
              firstNameTextField.setFocusable(e);
              numberTextField.setEditable(e);
              numberTextField.setFocusable(e);
         // a method for setting grid bag constraints
         private GridBagConstraints getConstraints(int gridx, int gridy,
              int gridwidth, int gridheight, int anchor)
              GridBagConstraints c = new GridBagConstraints();
              c.insets = new Insets(5, 5, 5, 5);
              c.ipadx = 0;
              c.ipady = 0;
              c.gridx = gridx;
              c.gridy = gridy;
              c.gridwidth = gridwidth;
              c.gridheight = gridheight;
              c.anchor = anchor;
              return c;
    class AutoSelect implements FocusListener
         public void focusGained(FocusEvent e)
              if(e.getComponent() instanceof JTextField)
                   JTextField t = (JTextField) e.getComponent();
                   t.selectAll();
         public void focusLost(FocusEvent e){}
    class IntFilter implements KeyListener
         public void keyTyped(KeyEvent e)
              char c = e.getKeyChar();
              if ( c !='0' && c !='1' && c !='2' && c !='3' && c !='4' && c !='5'
                   && c !='6' && c !='7' && c !='8' && c !='9')
                   e.consume();
         public void keyPressed(KeyEvent e){}
         public void keyReleased(KeyEvent e){}
    class ButtonPanel extends JPanel
         public JButton addButton,
              editButton,
              deleteButton,
              acceptButton,
              cancelButton,
              exitButton;
         public ButtonPanel()
              // create maintenance button panel
              JPanel maintPanel = new JPanel();
              maintPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
              // add button
              addButton = new JButton("Add");
              addButton.addActionListener(new AddListener());
              maintPanel.add(addButton);
              // edit button
              editButton = new JButton("Edit");
              editButton.addActionListener(new EditListener());
              maintPanel.add(editButton);
              // delete button
              deleteButton = new JButton("Delete");
              deleteButton.addActionListener(new DeleteListener());
              maintPanel.add(deleteButton);
              // accept button
              acceptButton = new JButton("Accept");
              acceptButton.setEnabled(false);
              acceptButton.addActionListener(new AcceptListener());
              maintPanel.add(acceptButton);
              // cancel button
              cancelButton = new JButton("Cancel");
              cancelButton.setEnabled(false);
              cancelButton.addActionListener(new CancelListener());
              maintPanel.add(cancelButton);
              // create exit button panel
              JPanel exitPanel = new JPanel();
              exitPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
              // exit button
              exitButton = new JButton("Exit");
              exitButton.addActionListener(new ExitListener());
              exitPanel.add(exitButton);
              // add panels to the ButtonPanel
              setLayout(new BorderLayout());
              add(maintPanel, BorderLayout.CENTER);
              add(exitPanel, BorderLayout.SOUTH);
         public void setAddEditMode(boolean e)
              addButton.setEnabled(!e);
              editButton.setEnabled(!e);
              deleteButton.setEnabled(!e);
              acceptButton.setEnabled(e);
              cancelButton.setEnabled(e);
    class AddListener implements ActionListener
         PlayerDisplayPanel playerPanel;
         ButtonPanel buttonPanel;
         Player newPlayer;
         public void actionPerformed(ActionEvent e)
              newPlayer = new Player();
              playerPanel.clearFields();
              buttonPanel.setAddEditMode(true);
              playerPanel.setAddEditMode(true);
    class EditListener implements ActionListener
         ButtonPanel buttonPanel;
         PlayerDisplayPanel playerPanel;
         public void actionPerformed(ActionEvent e)
              buttonPanel.setAddEditMode(true);
              playerPanel.setAddEditMode(true);
    class DeleteListener implements ActionListener
         teamSelectorPanel selectorPanel;
         PlayerDisplayPanel playerPanel;
         ArrayList<Player>team;
         public void actionPerformed(ActionEvent e)
              Player p = selectorPanel.getCurrentPlayer();
              team.remove(p);
              TeamIO.saveTeam();
              selectorPanel.fillComboBox(team);
              selectorPanel.selectPlayer(team.get(0));
              playerPanel.showPlayer(team.get(0));
              selectorPanel.playerComboBox.requestFocusInWindow();
    class AcceptListener implements ActionListener
         teamSelectorPanel selectorPanel;
         PlayerDisplayPanel playerPanel;
         ButtonPanel buttonPanel;
         ArrayList<Player>team;
         Player newPlayer;
         public void actionPerformed(ActionEvent e)
              if (isValidData())
                   if (newPlayer != null)
                        newPlayer = playerPanel.getPlayer();
                        team.add(newPlayer);
                        TeamIO.saveTeam();
                        selectorPanel.fillComboBox(team);
                        selectorPanel.selectPlayer(newPlayer);
                        newPlayer = null;
                   else
                        Player p = selectorPanel.getCurrentPlayer();
                        Player newPlayer = playerPanel.getPlayer();
                        p.setLastName(newPlayer.getLastName());
                        p.setFirstName(newPlayer.getFirstName());
                        p.setNumber(newPlayer.getNumber());
                        TeamIO.saveTeam();
                        selectorPanel.fillComboBox(team);
                        selectorPanel.selectPlayer(p);
                        playerPanel.showPlayer(selectorPanel.getCurrentPlayer());
                   playerPanel.setAddEditMode(false);
                   buttonPanel.setAddEditMode(false);
                   selectorPanel.playerComboBox.requestFocusInWindow();
         public boolean isValidData()
              return SwingValidator.isPresent(playerPanel.lastNameTextField, "Last Name")
                   && SwingValidator.isPresent(playerPanel.firstNameTextField, "First Name")
                   && SwingValidator.isPresent(playerPanel.numberTextField, "Number")
                   && SwingValidator.isInteger(playerPanel.numberTextField, "Number");
    class CancelListener implements ActionListener
         Player newPlayer;
         PlayerDisplayPanel playerPanel;
         ButtonPanel buttonPanel;
         teamSelectorPanel selectorPanel;
         public void actionPerformed(ActionEvent e)
              if (newPlayer != null)
                   newPlayer = null;
              playerPanel.setAddEditMode(false);
              playerPanel.showPlayer(selectorPanel.getCurrentPlayer());
              buttonPanel.setAddEditMode(false);
              selectorPanel.playerComboBox.requestFocusInWindow();
    class ExitListener implements ActionListener
         public void actionPerformed(ActionEvent e)
              System.exit(0);
    class SwingValidator
         public static boolean isPresent(JTextComponent c, String title)
              if(c.getText().length()==0)
                   showMessage(c, title + " is a required field.\n" + "Please re-enter.");
                   c.requestFocusInWindow();
                   return false;
              return true;
         public static boolean isInteger(JTextComponent c, String title)
              try
                   int i = Integer.parseInt(c.getText());
                   return true;
              catch(NumberFormatException e)
                   showMessage(c,title+" must be an integer.\n"+"Please re-enter.");
                   c.requestFocusInWindow();
                   return false;
         private static void showMessage(JTextComponent c, String message)
              JOptionPane.showMessageDialog(c, message, "Invalid Entry", JOptionPane.ERROR_MESSAGE);
    }

  • Public int move(CDRack anotherRack)

    I have problems with method: move(CDRack anotherRack).
    It removes CDs from anotherRack, but the rack I'm trying to fill in with anotherRack's CDs is filled with a one same CD from the anotherRack not various CDs as it should.. hard to explain.:)
    Is some willing to give me tips? And is there some other way
    to use insert method with the help of the move-method?
    /**Class CDRack represents collections of compact discs. Discs are
    located in the rack in slots numbered from zero upwards.The discs are
    represented by Record objects and empty slots by null values. */
    public class CDRack extends Object { 
      private Record[] collection;
    /**Creates a new, empty CD rack. Parameters:size - the size of the new
    rack, i.e. the number of slots it has */
        public CDRack(int size) {
           collection = new Record[size];   
           this.size = size;
    /**Inserts a cd in the given rack slot if the slot in question is
    empty. Parameters: disc - the cd to be added in the rackslot - the
    number of a (hopefully empty) slot
    Returns: a boolean value indicating if the insertion was successful.
        public boolean insert(Record disc, int slot) { 
           if (collection[slot]==null)) {    
             collection[slot] = record;    
             return true; 
           else return false; 
    /** Inserts the given cd in the first empty rack slot (if there is even
    one empty slot in the rack).
    Parameters: disc - the disc to be added in the rack
    Returns:
    the number of the slot where the disc was added, or a negative number
    if the rack was already full */
        public int insert(Record disc) {
           for(slot=0; slot<collection.length; slot++) {
             if(collection[slot]==null) {
                collection[slot] = disc;
                return slot;
           return -1; //not enough place
    /** Moves all the discs from the given cd rack to this rack. The cds
    from the other rack are inserted in the empty slots of this rack (in
    ascending numerical order of slot numbers) in the order in which they
    are located in the other rack. The moved discs are removed from their
    original rack. Even if there is not enough space for all the discs in
    this rack, as many cds are moved as possible.
    Parameters:
    anotherRack - another rack whose cds are to be moved into this one
    Returns:
    the number of cds moved from the other rack to this one */
        public int move(CDRack anotherRack) {
           int howMuchPlace = this.getSize() - this.getNumberOfCDs();
             if(anotherRack.getNumberOfCDs() <= howMuchPlace) {
                for(int i=0; i<anotherRack.getNumberOfCDs()+1; i++) {
                  this.insert(disc);
                for(slot=0; slot<anotherRack.getNumberOfCDs()+1; i++) {
                  anotherRack.remove(slot);
                return anotherRack.getNumberOfCDs();
            if(anotherRack.getNumberOfCDs() > howMuchPlace) {
                for(int i=0; i<howMuchPlace+1; i++) {
                  this.insert(disc);
                for(slot=0; slot<howMuchPlace+1; i++) {
                  anotherRack.remove(slot);
                return howMuchPlace;
             return -1;

    I'm about to leave the office (it's 7PM in London and
    there at least a dozen beers with my name on them ;)
    but I'll take a look on Monday and see how you got
    on.Sheesh. Must be Christmas or something :)
    You still need to implement organize() and sortAlphabetically(), plus move the classes to their own files and modify the parameter names to match the assignment.
    But, apart form that, here's what you wanted.
    Now, I realy am going to ge those beers...
    public class Maria2
         static class Record {}
         static class CDRack
              private Record[] mRecords;
              CDRack(int size) { mRecords= new Record[size]; }
              int find(Record disk)
                   for (int i= 0; i < mRecords.length; i++) {
                        if (mRecords.equals(disk))
                             return i;
                   return -1;
              Record getCD(int index)
                   if (index < 0 || index >= mRecords.length)
                        return null;
                   return mRecords[index];
              int getNumberOfCDs() { return getSize() -available(); }
              int getSize() { return mRecords.length; }
              int insert(Record record)
                   int index= 0;
                   for (; index < mRecords.length && mRecords[index] != null; index++);
                   if (insert(record, index))
                        return index;
                   return -1;
              boolean insert(Record record, int index)
                   if (index >= mRecords.length)
                        return false;
                   if (mRecords[index] != null)
                        return false;
                   mRecords[index]= record;
                   return true;
              private int available()
                   int available= 0;
                   for (int i= 0; i < mRecords.length; i++) {
                        if (mRecords[i] == null )
                             available++;
                   return available;
              Record remove(int index)
                   Record record= getCD(index);
                   mRecords[index]= null;
                   return record;
              int move(CDRack source)
                   int moved= 0;
                   for (int i= 0; i< source.getSize(); i++) {
                        Record record= source.getCD(i);
                        if (record == null)
                             continue;
                        if (insert(record) < 0)
                             break;
                        source.remove(i);
                        moved++;
                   return moved;
         public static void main(String[] argv)
              CDRack rack1= new CDRack(32);
              CDRack rack2= new CDRack(18);
              for (int i= 0; i< rack1.getSize()/2; i++)
                   rack1.insert(new Record(), i*2);
              for (int i= 0; i< rack2.getSize(); i++)
                   rack2.insert(new Record(), i);
              System.err.println("Rack one has " rack1.getNumberOfCDs() " records");
              System.err.println("Rack two has " rack2.getNumberOfCDs() " records");
              int moved= rack1.move(rack2);
              System.err.println(moved +" records were moved");
              System.err.println("Rack one has " rack1.getNumberOfCDs() " records");
              System.err.println("Rack two has " rack2.getNumberOfCDs() " records");

  • Null value for int and datetime date type in xml schema

    hi:
    I am embarrassed by a qustion in xml schema; i defined a xml schema file like
    this:
    <elementFormDefault="qualified" attributeFormDefault="qualified">
    <xs:element name="test">
    <xs:annotation>
    <xs:documentation>Comment describing your root element</xs:documentation>
    </xs:annotation>
    <xs:complexType>
    <xs:sequence>
    <xs:element name="name" type="xs:string"/>
    <xs:element name="password" type="xs:string" nillable="true"/>
    <xs:element name="user" type="xs:int" nillable="true"/>
    <xs:element name="s_time" type="xs:dateTime"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:schema>
    and I send this file to workflow clientrequest() node, I wanted to receive data
    in this schema file.but when i send null value to the element "user" and "s_time"
    in workshop test tool(test soap),and use function in xmlbean like isNilUser or
    isNilStime, one error occur.
    I don't kown why, I had to ask the engineer of bea in china, one told me a bug.
    is that true?

    Visakh16 I cant agree more with you on it, it is good but in production u cant have them change maxrows. I think
    Patrick  Hurst is a better option. debug the package have it running and move up
    Please mark as helpful and propose as answer if you find this as correct!!! Thanks,Dia Agha .
    Hmm..Why do you need to change it in production?
    What I suggested was to tweak the setting in dev machine so that it interprets the Excel file datatypes correctly when doing development. Once mapping is set correctly then it will work fine when in production or in any other environment. The tweaking is
    just to make sure it interprets the datatype correctly at design time and has nothing to do with production deployment 
    Please Mark This As Answer if it solved your issue
    Please Mark This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Date from a string and int value in ssis

    hi so my table is as follows
    active      expirymonth     
    expiryyear
    0              October                         2014
    0              February                            2015
    1               January                        2012
    and so on
    now my requirement is that if active =0 then in a new table lets say LASTDATE and they want a date with the last day of the expiry month and year  and if active is anything else write NULL for eg
    LASTDATE
    10/31/2014
    02/28/2015
    NULL
    I went to derived tables and made a new table called lastdate. What expression do i build in the expression builder to get the required result as i could not find a way to convert the text into int and then into a date

    Hi Bharatb111,
    If you want to achieve this using Derived Columns transform, you have to use following expression to first convert the month name value to integer:
    ([expirymonth]==”January”)?1:([expirymonth]==“February”)?2: ([expirymonth]==”March”)?3:([expirymonth]==“April”)?4:5
    However, if we need to validate a couple of or even all of twelve months, the expression validation will be failed. So, the Derived Column approach is impossible.
    To achieve your goal, you can use a Script Component to perform the date format conversion. This way, we can convert “dd/MMMM/yyyy(such as “01/October/2014”) format string value to “MM/dd/yyyy” (such as “10/01/2014”), and assign this value to a new output
    column (assuming its name is “DateVal” and its data type is DT_DATE) of the Script Component. Then, we can drag a Derived Column under the Script Component and connect them. In the Derived Column, we can add a new column named “LASTDATE” with the following
    expression:
    ([active]==0)?DATEADD(“d”,-1, DATEADD(“Month”),1,DateVal]):NULL(DT_DATE)
    For the Script Component code snippet, please refer to Reza’s answer:
    http://social.msdn.microsoft.com/Forums/sqlserver/en-US/1661339c-252c-4197-9cfd-943e1d86b573/convert-a-string-to-date-format?forum=sqlintegrationservices 
    Hope this helps.
    Regards,
    Mike Yin
    TechNet Community Support

  • Need help returning an Int!!!

    here is the code for my sport quiz class:
    import javax.swing.*;
    public class Sport
         public static int main (String []args)
    Object[] sportValues = { "Freddie", "jimbo", "the destroyer" };
    Object sportq1;
    Object[] sportValues2 = { "David Beckham", "Alessandro Del Piero",
    "Michael Ballack" };
    Object sportq2;
    Object[] sportValues3 = { "6", "10", "14" };
    Object sportq3;
    int sportScore = 0;
    String message;
    //............QUESTION 1..............
    sportq1 = JOptionPane.showInputDialog(null, "Question 1: What nickname is given to england cricketer andrew flintoff?", "selection", JOptionPane.YES_NO_CANCEL_OPTION, null,
    sportValues, sportValues[0]);
    if (sportq1.equals(sportValues[0]))
    message = "CORRECT!";
    JOptionPane.showMessageDialog(null, message);
    sportScore = (sportScore+1);
         else
         message = "WRONG!";
         JOptionPane.showMessageDialog(null, message);
         //............QUESTION 2.............
    sportq2 = JOptionPane.showInputDialog(null, "Question 2: Who scored italy's second goal in the world cup final?", "selection", JOptionPane.YES_NO_CANCEL_OPTION, null,
    sportValues2, sportValues2[0]);
    if (sportq2.equals(sportValues2[1]))
    message = "CORRECT!";
    JOptionPane.showMessageDialog(null, message);
    sportScore = (sportScore+1);
         else
         message = "WRONG!";
         JOptionPane.showMessageDialog(null, message);
         //............QUESTION 3.............
    sportq3 = JOptionPane.showInputDialog(null, "Question 3: how many players are there in an ice hockey team?", "selection", JOptionPane.YES_NO_CANCEL_OPTION, null,
    sportValues3, sportValues3[0]);
    if (sportq3.equals(sportValues3[0]))
    message = "CORRECT!";
    JOptionPane.showMessageDialog(null, message);
    sportScore = (sportScore+1);
         else
         message = "WRONG!";
         JOptionPane.showMessageDialog(null, message);
         return sportScore;
    i am trying to return the 'sportScore' int to a main quiz class but for some reason it hasnt worked...
    can anyone tell me what i have done wrong?
    thanks alot!

    this is my main quiz class:
    import javax.swing.*;
    public class Quiz
         public static void main (String []args)
             Object[] possibleValues = { "Sport", "Music", "General Knowledge", "TV and Film", "Display Score Board" };
             Object choice;
             do
          choice = JOptionPane.showInputDialog(null,"Welcome to my quiz\nPlease select you category:", "selection", JOptionPane.YES_NO_CANCEL_OPTION, null,
          possibleValues, possibleValues[0]);
          if  (choice.equals(JOptionPane.CANCEL_OPTION))
        System.exit(0);
        if (choice.equals(possibleValues[0]))
            Sport.doQuiz();
         if (choice.equals(possibleValues[1]))
            Music.doQuiz();
         if (choice.equals(possibleValues[2]))
            General.doQuiz();
        if (choice.equals(possibleValues[3]))
            TV.doQuiz();
        if (choice.equals(possibleValues[4]))
            int sportScore = Sport.doQuiz();
            int tvScore = TV.doQuiz();
            int musicScore = Music.doQuiz();
            int generalScore = General.doQuiz();
            int totalScore = (sportScore+tvScore+musicScore+generalScore);
            JOptionPane.showMessageDialog(null,"Thankyou for taking my quiz!\nhere are your results:\nSport: "
            + sportScore + "/3\nMusic: " + musicScore + "/3\nGeneral Knowledge: "
            + generalScore + "/3\nTV and Film: " + tvScore +"/3\n\nTOTAL: "
            + totalScore + "/12!");
        while(!(choice.equals(possibleValues[4])));
        }as you can see i have more than just the sport category but once i know how to do that one i will be able to do the rest...
    now here is my sport class:
    import javax.swing.*;
    public class Sport
           public static int doQuiz()
              Object[] sportValues = { "Freddie", "jimbo", "the destroyer" };
                Object sportq1;
              Object[] sportValues2 = { "David Beckham", "Alessandro Del Piero",
    "Michael Ballack" };
                Object sportq2;
              Object[] sportValues3 = { "6", "10", "14" };
                Object sportq3;
                int sportScore = 0;
                String message;
         //............QUESTION 1..............
                sportq1 = JOptionPane.showInputDialog(null, "Question 1: What nickname is given to england cricketer andrew flintoff?", "selection", JOptionPane.YES_NO_CANCEL_OPTION, null,
                sportValues, sportValues[0]);
                if (sportq1.equals(sportValues[0]))
                  message = "CORRECT!";
            JOptionPane.showMessageDialog(null, message);
            sportScore = (sportScore+1);
             else
                 message = "WRONG!";
              JOptionPane.showMessageDialog(null, message);
             //............QUESTION 2.............
                sportq2 = JOptionPane.showInputDialog(null, "Question 2: Who scored italy's second goal in the world cup final?", "selection", JOptionPane.YES_NO_CANCEL_OPTION, null,
                sportValues2, sportValues2[0]);
                if (sportq2.equals(sportValues2[1]))
                  message = "CORRECT!";
            JOptionPane.showMessageDialog(null, message);
              sportScore = (sportScore+1);
             else
             message = "WRONG!";
             JOptionPane.showMessageDialog(null, message);
             //............QUESTION 3.............
                sportq3 = JOptionPane.showInputDialog(null, "Question 3: how many players are there in an ice hockey team?", "selection", JOptionPane.YES_NO_CANCEL_OPTION, null,
                sportValues3, sportValues3[0]);
                if (sportq3.equals(sportValues3[0]))
                  message = "CORRECT!";
            JOptionPane.showMessageDialog(null, message);
              sportScore = (sportScore+1);
             else
                 message = "WRONG!";
              JOptionPane.showMessageDialog(null, message);
             return sportScore;
    }i am tring to return sportScore from the sport class to the main quiz class, at the moment instead of getting the sportScore at the end of the quiz class it is now running the whole sport class again!
    what have i done wrong?
    ta

  • Convert byte array to table of int

    [http://www.codeproject.com/KB/database/PassingArraysIntoSPs.aspx?display=Print|http://www.codeproject.com/KB/database/PassingArraysIntoSPs.aspx?display=Print] Hello friends.
    I'm pretty new with PL/SQL.
    I have code that run well on MSSQL and I want to convert it to PL/SQL with no luck.
    The code converts byte array to table of int.
    The byte array is actually array of int that was converted to bytes in C# for sending it as parameter.
    The TSQL code is:
    CREATE FUNCTION dbo.GetTableVarchar(@Data image)
    RETURNS @DataTable TABLE (RowID int primary key IDENTITY ,
    Value Varchar(8000))
    AS
    BEGIN
    --First Test the data is of type Varchar.
    IF(dbo.ValidateExpectedType(103, @Data)<>1) RETURN
    --Loop thru the list inserting each
    -- item into the variable table.
    DECLARE @Ptr int, @Length int,
    @VarcharLength smallint, @Value Varchar(8000)
    SELECT @Length = DataLength(@Data), @Ptr = 2
    WHILE(@Ptr<@Length)
    BEGIN
    --The first 2 bytes of each item is the length of the
    --varchar, a negative number designates a null value.
    SET @VarcharLength = SUBSTRING(@Data, @ptr, 2)
    SET @Ptr = @Ptr + 2
    IF(@VarcharLength<0)
    SET @Value = NULL
    ELSE
    BEGIN
    SET @Value = SUBSTRING(@Data, @ptr, @VarcharLength)
    SET @Ptr = @Ptr + @VarcharLength
    END
    INSERT INTO @DataTable (Value) VALUES(@Value)
    END
    RETURN
    END
    It's taken from http://www.codeproject.com/KB/database/PassingArraysIntoSPs.aspx?display=Print.
    The C# code is:
    public byte[] Convert2Bytes(int[] list)
    if (list == null || list.Length == 0)
    return new byte[0];
    byte[] data = new byte[list.Length * 4];
    int k = 0;
    for (int i = 0; i < list.Length; i++)
    byte[] intBytes = BitConverter.GetBytes(list);
    for (int j = intBytes.Length - 1; j >= 0; j--)
    data[k++] = intBytes[j];
    return data;
    I tryied to convert the TSQL code to PL/SQL and thats what I've got:
    FUNCTION GetTableInt(p_Data blob)
    RETURN t_array --t_array is table of int
    AS
    l_Ptr number;
    l_Length number;
    l_ID number;
    l_data t_array;
    BEGIN
         l_Length := dbms_lob.getlength(p_Data);
    l_Ptr := 1;
         WHILE(l_Ptr<=l_Length)
         loop
              l_ID := to_number( DBMS_LOB.SUBSTR (p_Data, 4, l_ptr));
              IF(l_ID<-2147483646)THEN
                   IF(l_ID=-2147483648)THEN
                        l_ID := NULL;
                   ELSE
                        l_Ptr := l_Ptr + 4;
                        l_ID := to_number( DBMS_LOB.SUBSTR(p_Data, 4,l_ptr));
                   END IF;
                   END IF;
    l_data(l_data.count) := l_ID;
              l_Ptr := l_Ptr + 4;
         END loop;
         RETURN l_data;
    END GetTableInt;
    This isn't work.
    This is the error:
    Error report:
    ORA-06502: PL/SQL: numeric or value error: character to number conversion error
    06502. 00000 - "PL/SQL: numeric or value error%s"
    I think the problem is in this line:
    l_ID := to_number( DBMS_LOB.SUBSTR (p_Data, 4, l_ptr));
    but I don't know how to fix that.
    Thanks,
    MTs.

    I'd found the solution.
    I need to write:
    l_ID := utl_raw.cast_to_binary_integer( DBMS_LOB.SUBSTR(p_Data, 4,l_ptr));
    instead of:
    l_ID := to_number( DBMS_LOB.SUBSTR (p_Data, 4, l_ptr));
    The performance isn't good, it's take 2.8 sec to convert 5000 int, but it's works.

  • Convert jstring to char array or int array

    Hi all, please help with the following code. I've tested this code with hard coded char array and it works. Now I have to get the char array from parameter "param1" which is passed from Java.
    The following code compiled with error message:
    error C2223: left of '->GetStringUTFChars' must point to struct/union
    JNIEXPORT void JNICALL Java_DongleSet_DongleWrite(JNIEnv *env,jobject obj,jstring param1){
    char HaspBuffer[500]=(char)env->GetStringUTFChars(param1,NULL);
    int Service=MEMOHASP_WRITEBLOCK;
    int SeedCode=300;
    int LptNum=0;
    int Pass1=pass1;
    int Pass2=pass2;
    int p1=0;
    int p2=12;
    int p3=0;
    int p4=(int)HaspBuffer;
    hasp(Service,SeedCode,LptNum,Pass1,Pass2,&p1,&p2,&p3,&p4);
    I've tried this:char HaspBuffer[500]=env->GetStringUTFChars(param1,NULL);
    And this:char HaspBuffer[500]=(*env)->GetStringUTFChars(param1,NULL);
    All give me errors.
    Please help.

    char * HaspBuffer=(*env)->GetStringUTFChars(param1,NULL); When writing pure C, you have to supply the JNIEnv as first arg to every JNIEnv function pointer.char * HaspBuffer=(*env)->GetStringUTFChars(env, param1, NULL);Look here: http://developer.java.sun.com/developer/onlineTraining/Programming/JDCBook/jnistring.html

Maybe you are looking for

  • How to use a custom.dll in forms 6i

    Hi, i have made a small dll using a icon-making software, that software has made a .dll of the icon I made in that software Now i want to use that .dll in my forms 6i. (client/server) the dll contains only one icon named 'Icon1' would any one please

  • Channel stopped by administrative task - ADAPTER.JAVA_EXCEPTION

    Hi Guys,              Adapter engine at RWB has the following error message. ==== Events on Server 44769350 ==== Adapter Engine, message: Fatal DeleteJob (Default Delete Job) failed. (Details: Code: MS.JOB.DELETE, Location: com.sap.aii.af.ra.ms.impl.

  • Double messages in Mail.

    Hmm- this is a new one by me. I'm running 10.5.6 on a 1.8GHz PowerPC G5. After a few weeks of weirdness on my Mac, and doing multiple re-installs of the System, I've finally gotten things worked out. To make a really long story short: bad RAM. Over t

  • Attaching photos as a file

    How can you attach a photo file without the actual photo showing on the email. If I go to the "Attach" not all my photos are there from IPhoto. Some are, some are not. Is there a way to have them copy over to the "Pictures" on Finder? Thanks

  • Mouse quits w/printer connected to airport extreme

    After 2+ yrs w/ no problems, now, mice will not move cursor when HP PSC2410 is connected to Airport Extreme, internet is OK. If I plug the printer directly into the mini, mice work fine. What the........!&%$