Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link

Aabha Varma

Greenhorn
+ Follow
since Jan 12, 2005
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Aabha Varma

Hi

I am playing around with switch statement. I have a big doubt.
check these two code snippets
int j = 10
switch(j){
case 1 : int k = 5;methodA(k);break;
case 2 : int k = 10; methodA(k);break;
}
this gives a compilation error saying variable defined already
but the one below doesnt ..
int j = 10
switch(j){
case 1 : {int k = 5;methodA(k);break};
case 2 : {int k = 10; methodA(k);break};
}
why is it so ?

Second thing
int j = 10
switch(j){
case 1 : int k = 5;methodA(k);break;
case 2 : k=10;methodA(k);break;
}
Its defined already in case1, now it gives compilation errror with initialization....but in case 1 its already initialized.

Any one out there to help me ??
15 years ago
I want to override the default size of the combo popup.

issue is :-
the popup size now depends on the number of values, if the value is one and data display area is less, it shows a horizontal scroll bar and so cant select the element

Any suggestions?
16 years ago
I am using random file to write some data delimeted by '$' sign.
There is a function which reads the data from file.

but at time when it reads, it takes some strings which are not there in the file.
why is this happening? Is it because there is a limit to the number of characters that can be read.

At times i am also getting StreamReaderCorrupted Exception.
Can anybody explain what are possible reasons this could arise
16 years ago
I have a program that creates 1000's of value object. All of them are in memory. When i run the program for the first time, its pretty fast and then on subsequent run its damn slow. I think its becasue GC is not happening....

ihave a method implementaion like this. could you tell me what needs to be done so that the objects are garbage collected

arrayList method(){
for(i = 0 ; i < n i++){
ValueObject v = new ValueObject();
arrayList.add(v) ;
}
return arrayList;
}

Now my question lies.. if after addding to arrayList can i make the valueobject v to null ??
can you direct me to some good implementation of effective garbage collection.
16 years ago
Hi,

I have added a split pane to my frame.
Split panes left component contains a scrollpane, to which i have added a panel.And to this panel i am adding an image.
And to the right another panel.

if i chagne the split slider, i wanted the image to occupy the space provided. how to do that.

When i zoom in i increase the size of image.. and also the panel on which it is drawn,, But scroll bars are not comming..

So how to go abt it

Thanks in advance,
16 years ago
I have a tree with two levels.

Parent node contains the information, depending on which child nodes colour should change.

Is it possible that when i am rendering the parent (by checking the node level) can i render the child nodes...as i have the info.

Can anyone help me out.

Regards,
16 years ago
I have a checkbox and initialised with an icon.
depending on some value i need to update the icons...
but checkbox should remain non editable...........

What happens now is when i make teh checkbox disabled, both the
label as well as icons are greyed out..

How to go abt this ?
17 years ago

Originally posted by Ilja Preuss:


A linear search in 1000 objects shouldn't take much longer than a few milliseconds. If it does, you should try to find to find out why first.

How long *does* it take? Can you show us some code?



I havent done any coding on this. Its in desing phase only.

A few milliseconds(as quoted by you) is to search 1000 objects with a single attribute right? so if there are 10 such attributes.. 10 * few milliseconds..
if there are 100 such request to search it comes to 10*100*few milliseconds..

i.e., it might take a few seconds right?
i am supposed to do 1000 such request in 1 second.
So i am thinking of objects other than arraylist and hashmap.

lemme see if i can write some code on it, whcih i think it takes weeks.

:roll:
17 years ago
Hi

An object is having 10 different attributes.
And they are loaded into the memory in junks.
There can be 1000 such objects added in one go.

These objects that are already added will be of no use after a particular condition. But that condition is again a random thing. sometimes it may last for a long time or it may notbe used in few seconds.

The whole program may run for 10 -20 minutes.
And the number of search may be 100-150 times in a minute or less than a minute. These search may be for the differnt combination of object parameter.

I havent tested the stuff so am not able to give you the exact figures.
These figures i have mentioned is very much possible.
17 years ago
Using hashmaps doesnt give a feasible solution. Because if my object has 3 different attributes, depending on the value i should create and put them in 3 different hashmap, which is unnecessarily loading the memory thrice with the same objects.

I had just look at Java Spaces. But its effective only for distributed system. There also it duplicates theobject at its server and local.
Is there any similar interface like java spaces....which can be used..
or can you suggest some idea regarding the structure of the object, so that if i give a size and color as parameter, i will get the result set, but without using two loops
17 years ago
Hi,

I have to work with large junks of data.
Assume i have a basket full of apples, which has its own specific colour,specific weight,specific place where it is imported.
I will taking all these details as a list to the client, by creating a Value object of apple.

Now the issue is if i want to do a query on size or place of import or other characteristics, i need to go through the entire list in a for loop and get the list. This is taking hell lot of time.
Is there any way of indexing the objects so that i can say, give me size x apples, it will return me all the size matching x.(Basically without going in the for loop). I dont want to store individual arraylist based on size, weight etc.. because it will eat up a lot of memory......

Something like the one implemented in oracle queries where clause.
So can anybody help me through.
17 years ago
Hi,

I have created two panels. And overridden the paint method.
some images are drawn on the main panel, and on top of it i am placing a glass panel, with set opaque as false.

I want to do some stuffs like glass painting..
where the background shouldnt change, but the one on the top should change.
But when i am doing a repaint() for the glasspanel objects, i am able to see the object moving in the glass panel, but the back ground remains blank..

I am attaching a rough work along with.
My intention is , to improve the performance, the one in the background remains as such but only the glasspanel repaint will be called..

Can anybody help me. or provide me with some good techniques to reach the goal.

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.*;

public class GlassClass extends JFrame
{
private JPanel panelMain ;
private JPanel panelGlass;
private int valuex;
private int valuey;
public GlassClass()
{

this.setSize(300,300);
panelMain = new MainPanel();
panelGlass = new GlassPanel();
panelGlass.setOpaque(true);

panelMain.setLayout(new BorderLayout());
panelMain.add(panelGlass,BorderLayout.CENTER);

this.getContentPane().add(panelMain, BorderLayout.CENTER);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

// if the method is commented, both the images on main panel and
// and glass panel are visibel
drawMethods();

this.setVisible(true);

}

private void drawMethods()
{
Thread A =new Thread()
{
public void run()
{
while(true)
{
try
{
this.sleep(50);
valuex = valuex+1;
valuey = valuey+1;
panelGlass.repaint();
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
};
A.start();
}
public static void main(String[] args)
{
GlassClass gc = new GlassClass();
}

class MainPanel extends JPanel
{
public MainPanel()
{

}

public void paint(Graphics g)
{
super.paint(g);
this.setBackground(Color.WHITE);
g.setColor(Color.RED);
g.fillRect(10,10,30,30);
}
}


class GlassPanel extends JPanel
{
public GlassPanel()
{

}

public void paint(Graphics g)
{
super.paint(g);
g.setColor(Color.GREEN);
//g.setXORMode(Color.RED);
g.fillOval(valuex,valuey,10,10);
g.fillRect(40,40,10,10);
}
}
}
17 years ago
If you want to create a class for each component, then you need to extend the super class.

say creating a button,,,
class SampleButton extends JButton..

And then you add this to container.
panel.add(new SampleButton());

To answer to the second part, if you want to add to the frame you need to get the contentpane and then add the components.

Hope this answers
17 years ago
Thanks Michael.

Its working perfectly.
17 years ago
Hi,

I am using BasicSliderUI only.
I have over written some of the methods. paintThump()...etc.

But i am getting the image at 0,0 position as well as a slider button.
My intention was to set the image on to the button.


Is there any link which tells more abt how to use this Component UI, Basic slider ui...etc with some example code.

Here is the code.

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import javax.swing.JSlider;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.SliderUI;
import javax.swing.plaf.basic.BasicSliderUI;

public class test extends JFrame
{
private JPanel cJPanel1 = new JPanel();
private JSlider cJSlider1 = new JSlider();
private ImageIcon image = new ImageIcon("c:\\image1");

public test()
{
try
{
jbInit();
}
catch(Exception e)
{
e.printStackTrace();
}

}

private void jbInit() throws Exception
{
cJPanel1.add(cJSlider1, null);
cJSlider1.setBackground(cJSlider1.getParent().getBackground());

DefaltSliderUI sliderUI = new DefaltSliderUI(cJSlider1);
cJSlider1.setUI(sliderUI);

this.getContentPane().add(cJPanel1, BorderLayout.CENTER);
}


class DefaltSliderUI extends BasicSliderUI
{
private JSlider cjSlider;
public DefaltSliderUI(JSlider cJSlider1)
{
super(cJSlider1);
this.cjSlider = cJSlider1;

}
public void paintThumb (Graphics g)
{
g.drawImage(image.getImage(),0,0, null); super.paintThumbg);

}
public void scrollDueToClickInTrack()
{
super.scrollDueToClickInTrack(1);
}
public void paintTrack(Graphics g)
{
g.setColor(Color.RED);
}

public void paint(Graphics g,JSlider cjSlider)
{
super.paint(g,cjSlider);
}
}

public static void main(String[] args)
{
test test = new test();
test.setSize(500,100);
test.setVisible(true);
}
}
17 years ago