Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Editable issues

Reply
Thread Tools

Editable issues

 
 
K
Guest
Posts: n/a
 
      01-29-2013
I made a java program and can't figure out why my uneditable text can still be edited. I have 2 classes in this program here's the secondary class:
import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JOptionPane;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;

public class GUI_two extends JFrame{

private JTextField item2;
private JTextField item3;
private JTextField item4;
private JPasswordField itempass;
ImageIcon image = new ImageIcon("star.png");
public GUI_two(){
super("Kale");
setLayout(new FlowLayout());
item2 = new JTextField(10);
add(item2);
item3 = new JTextField("Enter text here");
item3.setEditable(false);
add(item3);
item4 = new JTextField("Can't edit", 20);
item3.setEditable(false);
add(item4);
itempass = new JPasswordField ("Password");
add(itempass);
reg = new JButton("Button");
add(reg);
Icon b = new ImageIcon(getClass().getResource("Button 2.png"));
Icon a = new ImageIcon(getClass().getResource("Button.png"));
custom = new JButton("Custom", a);
custom.setRolloverIcon(b);
add(custom);

thehandler handler = new thehandler();
item2.addActionListener(handler);
item3.addActionListener(handler);
item4.addActionListener(handler);
itempass.addActionListener(handler);
reg.addActionListener(handler);
custom.addActionListener(handler);

}

private JButton reg;
private JButton custom;

private class thehandler implements ActionListener{
public void actionPerformed(ActionEvent event){
String string = "";
if(event.getSource()==item2){
string=String.format("field 2: %s", event.getActionCommand());}
else if (event.getSource()==item3)
string=String.format("field 3: %s", event.getActionCommand());
else if (event.getSource()==item4)
string=String.format("field 4: %s", event.getActionCommand());
else if (event.getSource()==itempass)
string=String.format("itempass is : %s", event.getActionCommand());


//JOptionPane.showMessageDialog(null, String.format("%s, event.getActionCommand()"));
JOptionPane.showMessageDialog(null, string);
}
}


}

here's the main class:
import javax.swing.JOptionPane;
import javax.swing.JFrame;

public class Kale_GUI {


public static void main(String[] args) {
String fn = JOptionPane.showInputDialog("Enter first number");
String sn = JOptionPane.showInputDialog("Enter second number");
int num1 = Integer.parseInt(fn) ;
int num2 = Integer.parseInt(sn) ;
int sum = num1 + num2;
JOptionPane.showMessageDialog(null, "The answer is "+sum, "The title", JOptionPane.PLAIN_MESSAGE);

GUI_two kale = new GUI_two();

kale.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
kale.setSize(500,500);
kale.setVisible(true);
}

}


 
Reply With Quote
 
 
 
 
Mikhail Vladimirov
Guest
Posts: n/a
 
      01-29-2013
> item3 = new JTextField("Enter text here");
> item3.setEditable(false);
> add(item3);
> item4 = new JTextField("Can't edit", 20);
> item3.setEditable(false);
> add(item4);

Probably because you did setEditable (false) on item3 twice, and didn't do it on item4?
 
Reply With Quote
 
 
 
 
Arved Sandstrom
Guest
Posts: n/a
 
      01-29-2013
On 01/29/2013 03:17 AM, Peter Duniho wrote:
> On Mon, 28 Jan 2013 22:21:25 -0800 (PST), Mikhail Vladimirov wrote:
>
>>> item3 = new JTextField("Enter text here");
>>> item3.setEditable(false);
>>> add(item3);
>>> item4 = new JTextField("Can't edit", 20);
>>> item3.setEditable(false);
>>> add(item4);

>> Probably because you did setEditable (false) on item3 twice, and didn't do it on item4?

>
> Copy/paste rears its ugly head again. A helper method would have prevented
> the mistake:

[ SNIP ]

Helper method probably best. I'd also name variables better, and
declare/define and do everything with them in one spot demarcated by WS,
if possible, e.g.:

private JTextField nameTextFld;
nameTextFld = new JTextField("Enter name");
nameTextFld.setEditable(false);
add(nameTextFld);
MyActionListener aLsnr = new MyActionListener();
nameTextFld.addActionListener(aLsnr);

We've had this discussion before, blocks also ensure that erroneous copy
& paste (for situations like this) also fails.

I barely ever use Swing, so I won't comment on the ActionListener
implementation. I do know it's fairly wrong-looking and just plain ugly.
I'm myself not going to have a spaghetti event handler that looks to see
who fired it out of many possibilities.

Main problem here is that in 2013 we still have people hand-cranking
Swing code. It's ugly, tedious, unedifying, error-prone code. It's worse
than JSF boilerplate and that's saying quite a lot.

..NET tooling has Java beat in this regard.

AHS
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      01-29-2013
On Mon, 28 Jan 2013 21:19:03 -0800 (PST), K <> wrote,
quoted or indirectly quoted someone who said :

>I made a java program and can't figure out why my uneditable text can still be edited


see sample code at http://mindprod.com/jgloss/jpasswordfield.html

it works fine with setEditable( false )

You made an error that would not likely have happened with more
meaningful names for your variables:

item3 = new JTextField("Enter text here");
item3.setEditable(false); <-- you meant true
item4 = new JTextField("Can't edit", 20);
item3.setEditable(false); <-- you meant item4

let me rename the vars:

canEnter= new JTextField("Enter text here");
canEnter.setEditable(false); <-- you meant true
cantEnter= new JTextField("Can't edit", 20);
canEnter.setEditable(false); <-- you meant cantEnter
--
Roedy Green Canadian Mind Products http://mindprod.com
The first 90% of the code accounts for the first 90% of the development time.
The remaining 10% of the code accounts for the other 90% of the development
time.
~ Tom Cargill Ninety-ninety Law
 
Reply With Quote
 
Arne Vajhøj
Guest
Posts: n/a
 
      01-30-2013
On 1/29/2013 5:27 AM, Arved Sandstrom wrote:
> Main problem here is that in 2013 we still have people hand-cranking
> Swing code. It's ugly, tedious, unedifying, error-prone code. It's worse
> than JSF boilerplate and that's saying quite a lot.
>
> .NET tooling has Java beat in this regard.


I strongly suspect that it is not:

lack of GUI builder tools => desire to hand write Swing code

but instead:

desire to hand write Swing code => lack of GUI builder tools

Arne



 
Reply With Quote
 
Arved Sandstrom
Guest
Posts: n/a
 
      01-30-2013
On 01/29/2013 11:02 PM, Arne Vajhøj wrote:
> On 1/29/2013 5:27 AM, Arved Sandstrom wrote:
>> Main problem here is that in 2013 we still have people hand-cranking
>> Swing code. It's ugly, tedious, unedifying, error-prone code. It's worse
>> than JSF boilerplate and that's saying quite a lot.
>>
>> .NET tooling has Java beat in this regard.

>
> I strongly suspect that it is not:
>
> lack of GUI builder tools => desire to hand write Swing code
>
> but instead:
>
> desire to hand write Swing code => lack of GUI builder tools
>
> Arne
>

If I parse your English correctly, Arne, you're suggesting that folks
*prefer* to code Swing directly rather than make use of GUI builder
interfaces?

Man, I'm not sure I buy that. I've suffered through writing Swing code
from scratch a few times, I don't see how it's any more useful to do
that than hand-coding JSF Facelets .xhtml and backing bean boilerplate.
Which is to say, not useful at all. You gain nothing over using GUI
builder tools, and you lose time better spent on real logic.

AHS

 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      01-30-2013
Arved Sandstrom wrote:
> Arne Vajh�j wrote:
> > I strongly suspect that it is not:
> > lack of GUI builder tools => desire to hand write Swing code
> > but instead:
> > desire to hand write Swing code => lack of GUI builder tools

>
> If I parse your English correctly, Arne, you're suggesting that folks
> *prefer* to code Swing directly rather than make use of GUI builder
> interfaces?


No, he's suggesting that in this particular case the person might be deliberately
doing it by hand. I guess programmers do that when they want to learn what they're
actually doing.

> Man, I'm not sure I buy that. I've suffered through writing Swing code
> from scratch a few times, I don't see how it's any more useful to do
> that than hand-coding JSF Facelets .xhtml and backing bean boilerplate.
> Which is to say, not useful at all. You gain nothing over using GUI
> builder tools, and you lose time better spent on real logic.


Yes, even you have written Swing by hand. What's so odd that others might also?

Didn't the experience teach you about Swing? That wasn't useful?

--
Lew

 
Reply With Quote
 
Arved Sandstrom
Guest
Posts: n/a
 
      01-30-2013
On 01/30/2013 12:32 PM, Lew wrote:
> Arved Sandstrom wrote:
>> Arne Vajh�j wrote:
>>> I strongly suspect that it is not:
>>> lack of GUI builder tools => desire to hand write Swing code
>>> but instead:
>>> desire to hand write Swing code => lack of GUI builder tools

>>
>> If I parse your English correctly, Arne, you're suggesting that folks
>> *prefer* to code Swing directly rather than make use of GUI builder
>> interfaces?

>
> No, he's suggesting that in this particular case the person might be deliberately
> doing it by hand. I guess programmers do that when they want to learn what they're
> actually doing.
>
>> Man, I'm not sure I buy that. I've suffered through writing Swing code
>> from scratch a few times, I don't see how it's any more useful to do
>> that than hand-coding JSF Facelets .xhtml and backing bean boilerplate.
>> Which is to say, not useful at all. You gain nothing over using GUI
>> builder tools, and you lose time better spent on real logic.

>
> Yes, even you have written Swing by hand. What's so odd that others might also?
>
> Didn't the experience teach you about Swing? That wasn't useful?
>

During the learning phase, sure. Makes sense.

But in routine work, once I've gotten the technology, no, I don't want
to write all the tedious boilerplate. Swing, JSF, JPA etc - I generate
as much as I can if I can, or I wish I could if it's not possible. All I
really want to spend my time on is modifying the generated code.

AHS
 
Reply With Quote
 
Arne Vajhøj
Guest
Posts: n/a
 
      01-31-2013
On 1/30/2013 6:38 AM, Arved Sandstrom wrote:
> On 01/29/2013 11:02 PM, Arne Vajhøj wrote:
>> On 1/29/2013 5:27 AM, Arved Sandstrom wrote:
>>> Main problem here is that in 2013 we still have people hand-cranking
>>> Swing code. It's ugly, tedious, unedifying, error-prone code. It's worse
>>> than JSF boilerplate and that's saying quite a lot.
>>>
>>> .NET tooling has Java beat in this regard.

>>
>> I strongly suspect that it is not:
>>
>> lack of GUI builder tools => desire to hand write Swing code
>>
>> but instead:
>>
>> desire to hand write Swing code => lack of GUI builder tools
>>

> If I parse your English correctly, Arne, you're suggesting that folks
> *prefer* to code Swing directly rather than make use of GUI builder
> interfaces?


Correct.

> Man, I'm not sure I buy that. I've suffered through writing Swing code
> from scratch a few times, I don't see how it's any more useful to do
> that than hand-coding JSF Facelets .xhtml and backing bean boilerplate.
> Which is to say, not useful at all. You gain nothing over using GUI
> builder tools, and you lose time better spent on real logic.


A GUI builder is very fast to create something that from
simple to medium complexity. But if you need to create
something of high complexity you often end up having to
work around the GUI builder.

The generated code is usually much harder to read when
debugging.

And if you change IDE you risk to loose the capability
on existing code.

Anyway - there has been several GUI builders for Java.
JBuilder had one. NetBeans has tried twice I believe.
Eclipse has tried twice. No success. No widespread
usage.

And note that it is not really Java that is different
from the rest. It is really MS that is different from
the rest. GUI builders are not common in PHP, various X
etc..

Arne


 
Reply With Quote
 
Arne Vajhøj
Guest
Posts: n/a
 
      01-31-2013
On 1/30/2013 6:34 PM, Arved Sandstrom wrote:
> On 01/30/2013 12:32 PM, Lew wrote:
>> Arved Sandstrom wrote:
>>> Arne Vajh�j wrote:
>>>> I strongly suspect that it is not:
>>>> lack of GUI builder tools => desire to hand write Swing code
>>>> but instead:
>>>> desire to hand write Swing code => lack of GUI builder tools
>>>
>>> If I parse your English correctly, Arne, you're suggesting that folks
>>> *prefer* to code Swing directly rather than make use of GUI builder
>>> interfaces?

>>
>> No, he's suggesting that in this particular case the person might be
>> deliberately
>> doing it by hand. I guess programmers do that when they want to learn
>> what they're
>> actually doing.
>>
>>> Man, I'm not sure I buy that. I've suffered through writing Swing code
>>> from scratch a few times, I don't see how it's any more useful to do
>>> that than hand-coding JSF Facelets .xhtml and backing bean boilerplate.
>>> Which is to say, not useful at all. You gain nothing over using GUI
>>> builder tools, and you lose time better spent on real logic.

>>
>> Yes, even you have written Swing by hand. What's so odd that others
>> might also?
>>
>> Didn't the experience teach you about Swing? That wasn't useful?
>>

> During the learning phase, sure. Makes sense.
>
> But in routine work, once I've gotten the technology, no, I don't want
> to write all the tedious boilerplate. Swing, JSF, JPA etc - I generate
> as much as I can if I can, or I wish I could if it's not possible. All I
> really want to spend my time on is modifying the generated code.


That requires the generated code to be as good as handwritten code
to work.

That is rarely the case.

Arne


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Windows XP Pro clean install issues, SP2 issues too... Howie Computer Support 9 07-12-2005 04:47 PM
Windows XP Pro clean install issues, SP2 issues too... Howie Computer Support 0 07-06-2005 07:12 PM
Re: Windows XP Pro clean install issues, SP2 issues too... pcbutts1 Computer Support 0 07-06-2005 04:58 PM
Re: Windows XP Pro clean install issues, SP2 issues too... pcbutts1 Computer Support 0 07-06-2005 04:52 PM
SNMP Issues in Cisco Routers; Vulnerability Issues in TCP =?iso-8859-1?Q?Frisbee=AE?= MCSE 0 04-21-2004 03:00 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57