KunkalaGuntala Samba Siva Rao

Greenhorn
+ Follow
since Nov 06, 2003
Merit badge: grant badges
For More
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 KunkalaGuntala Samba Siva Rao

thank you, that helps..
20 years ago
i have around 10 popup screens and it has to work on click of a button
button1_click()
{
new PopupScreen1(ID)
}
class PopupScreen1 extends JDialog
{
private String ID;
public PopuPScreen1(Sting ID)
{
this.ID = ID;
try {
createComponents()
}
catch (Exception e)
{
e.printStackTrace();
}
}
public createComponents() {
//creats the swing components
setValues();
}
public void setValues()
{
//calls db procedure and sets values
}
}

as you see i need the dialog popup screen to popup only when the user clicks the button.
and each time it creates a new object
the question is
1. how to handle this to reduce memory problems.
2. sometimes the user may not click, so no need to instantiate
3. when user clicks the button for first time i want to create the object
4. for the second time, i want to just use the old object
5. how does the memory allocation work in this case for multiusers, will each user be allocated memory in the his PC on click or its all in server.
i am confused..please help.
20 years ago
I am trying to create a custom Label component
I am unable to find out
1. why this changes the default look and feel font color to black
2. though i set the color using setColor explicitly, it doesn't seem to change
thank you

[edited to fix formatting -JM]
[ November 17, 2003: Message edited by: Jason Menard ]
20 years ago
I am trying to create a custom Label component
I am unable to find out
1. why this changes the default look and feel font color to black
2. though i set the color using setColor explicitly, it doesn't seem to change
thank you
[code]
import java.awt.*;
import java.awt.font.*;
import java.text.*;
import javax.swing.*;
public class JMultilineLabel extends JComponent
{
private String text;
private Color color;
private Insets margin = new Insets(0,0,0,0);
private int maxWidth = Integer.MAX_VALUE;
private boolean justify;
private final FontRenderContext frc = new FontRenderContext(null, false, false);
private void morph()
{
revalidate();
repaint();
}
public String getText()
{
return text;
}
public void setText(String text)
{
String old = this.text;
this.text = text;
firePropertyChange("text", old, this.text);
if ((old == null) ? text!=null : !old.equals(text))
morph();
}
public void setColor(Color color) {
Color old = this.getForeground();
this.setForeground(color);
firePropertyChange("foreground", old, this.getForeground());
if (!color.equals(this.getForeground()))
{
}
}
public int getMaxWidth()
{
return maxWidth;
}
public void setMaxWidth(int maxWidth)
{
if (maxWidth <= 0)
throw new IllegalArgumentException();
int old = this.maxWidth;
this.maxWidth = maxWidth;
firePropertyChange("maxWidth", old, this.maxWidth);
if (old != this.maxWidth)
morph();
}
public boolean isJustified()
{
return justify;
}
public void setJustified(boolean justify)
{
boolean old = this.justify;
this.justify = justify;
firePropertyChange("justified", old, this.justify);
if (old != this.justify)
repaint();
}
public Dimension getPreferredSize()
{
return paintOrGetSize(null, getMaxWidth());
}
public Dimension getMinimumSize()
{
return getPreferredSize();
}
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
paintOrGetSize((Graphics2D)g, getWidth());
}
private Dimension paintOrGetSize(Graphics2D g, int width)
{
Insets insets = getInsets();
width -= insets.left + insets.right + margin.left + margin.right;
float w = insets.left + insets.right + margin.left + margin.right;
float x = insets.left + margin.left, y=insets.top + margin.top;
if (width > 0 && text != null && text.length() > 0)
{
AttributedString as = new AttributedString(getText());
as.addAttribute(TextAttribute.FONT, getFont());
AttributedCharacterIterator aci = as.getIterator();
LineBreakMeasurer lbm = new LineBreakMeasurer(aci, frc);
float max = 0;
while (lbm.getPosition() < aci.getEndIndex())
{
TextLayout textLayout = lbm.nextLayout(width);
if (g != null && isJustified() && textLayout.getVisibleAdvance() > 0.80 * width) textLayout = textLayout.getJustifiedLayout(width); if (g != null) textLayout.
20 years ago
yep, this is about the row and records returned.. thanks anyway.. )))
20 years ago
Resultset rs;
just a resultset object
rs =...
20 years ago

before opening the popup, i am trying to say a user message if there are no records returned..
-----
1.
if (rs==null)
doesn't seems to catch a empty resultset returned)
2.
if rs.next()
is used it is skipping to display one record in the popup.
how to get around this , i am hoping i don't have to make an extra database call or use another type of cursor
20 years ago
i got this one, thanks anyway
instead of passing objects like
"ClassName.this"
i was just passing "this"
thanks anyway
20 years ago
i have popup codes like this (too many around 12-20 popup screens) painted for demo.
most of them have a kind of 1-2 layout ie
the fields come dynamically from a resultset
i am guessing i can change the SQL code so that i can get the proper field names
eg
SELECT
FIELD1 AS DisplayName1,
FIELD2 AD DisplayName2
...
is there a way to dynamically adjust the layout to set the fields in a good way according to the recordset returned.
20 years ago
i guess its just the word that is confusing..
"reference is passed by value" is the correct answer..
this was an old example here..
20 years ago
I couldn't use cordlayout for some reasons, so i am trying to simulate a back button without creating many instances..
ie my first screen is invoked like this in Frame class
public void launchMainPanel()
{
System.out.println("Launch main panel");
mainPanelClass = new PCMainPanel(DataClass);
mainPanelClass.addComp1();
}
my second screen is invoked like this in another class
PCPanel1 p1 = new PCPanel1(data1);
p1.addComp2();
???
PCPanel1 p1 = new PCPanel1(data1, ???);
???
i have trouble to get this object here and pass it on to the next class...
i am trying to think how to pass the mainPanelClass to another class so that when back button is clicked i can call the method back without creating one more instance
btnBack.addActionListener(new ActionListener ()
{
public void actionPerformed(ActionEvent e)
{
mainPanel.addComp1();
}
});
---------------
so finally i need a back button working without creating more than one instance of same class
20 years ago
looks big, but the question context is in "passing object references only by value"
PCPanel1 p1 = new PCPanel1(data1);
p1.addComp2();
i have trouble passing the PCMainPanel object also here so that it can be called back by the back button using the reference (oops...reference passed by value..)
how to acheive this without creating one more instance or clone()
---------------------------------------------------------------------------
20 years ago
for some reasons i couldn't use the CORD Layout
Will it take more memory and process speed if i pass the object like shown below
class DATAClass{
private String dbName;
private String dbconn;
private Resultset rs;
public DATAClass(String databaseName, Connection conn) {
dbconn = conn;
dbName = databaseName);
}

public ResultSet GetMethod1(Connection conn, String id) throws SQLException {
CallableStatement sproc_stmt = conn.prepareCall("{call " + dbName + ".." + "PROC1" + " (?)}");
ResultSet sproc_result = DatabaseProxy.toResultSet(sproc_stmt);
return sproc_result;
}

public ResultSet GetMethod2(Connection conn, String id) throws SQLException {
}

..more methods here for each stored proc
}

class MAINClass {
public MAINClass(){
jbInit();
}
jbInit() {

DATAClass d1 = new DATAClass("dbname","conndetails");
//Invoke the first class and load components
Class1 c1 = new Class1(d1);
c1.load_components1();
}
}
import com.samples.DATAClass;
Class1 {
private DATAClass data1;
public Class1(DATAClass d1){
data1 = d1;
}
load_components1() {
EXECUTE data1.GetMethod1;
//Paint components
}
button_click() {
Class2 c2 = new Class2(data1, this);
}
}
import com.samples.DATAClass;
Class2 {
private DATAClass data2;
private Class1 c1;
public Class2(DATAClass data, Class1 class1 ){
data2 = data;
c1 = class1;
}
load_components2() {
data2.GetMethod2();
}
go_back() {
c1.load_components1();
}
}
20 years ago