Click here to Skip to main content
       

Java

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page  Show 
GeneralRe: Creating a class that extends more than one class.memberBill.Moo4 Oct '12 - 3:59 
Where do you read this? I got the Observable/Observer from the "Java - The complete reference 8th Ed. Ch 18, p541" and there is no reference to it being obsolete or as a candidate for it either.
 
What I want to do is create a class that extends AbstractAction and implements runnable. The actionPerformed will display a file open dialog allowing the user to select N files, these files are then stored in a File[] and the thread started when the dialog is closed to process the files. But I wanted the observable so I could 'emit' messages to the Observer (my UI) so I could say "Processing filename.ext..." as the processing can take a bit of time, hence the use of the thread and 'status message'. But of course if there is a better way of doing this then I'm all for learning.
 
The Events / Actions sounds sensible, are you able to give me a
link to something?
--
Bill

GeneralRe: Creating a class that extends more than one class.memberPeter_in_27804 Oct '12 - 11:36 
Blush | :O That's what I get for trying to make sense at midnight. I use "Java in a Nutshell, 5th ed". Observable/Observer are since Java 1.0 and the comment is "The Observable class and Observer interface are not commonly used. Most applications prefer the event-based notification model defined by the JavaBeans componenent framework and by the EventObject class and EventListener interface of this package. [java.util]" So I misread preference as superceding... I do remember the Event model being introduced (in Java 1.1) in response to a perceived hole in functionality.
Looks like you want to make your UI implement EventListener and have the worker thread spit out (your subclass of) EventObjects as required.
I'm sure there are plenty of examples floating around the web. (Java's like that Smile | :) ) I'd start with Mr G and something like "Java EventObject".
 
Good hunting,
Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012

AnswerRe: Creating a class that extends more than one class.memberpasztorpisti4 Oct '12 - 12:14 
Before starting any serious java tutorials its worth reading through the official beginner java tutorial: http://docs.oracle.com/javase/tutorial/index.html[^]
Read at least the "Trails Covering the Basics" paragraph and all of its subpages. Its a novice coder tutorial so you will progress with that quickly and you can gain a lot of important java-specific info from it that makes your work much easier. It worth at least a quicky reading even if you are lazy to try the examples!
QuestionRe: Creating a class that extends more than one class.memberMonster Maker21 Oct '12 - 21:08 
In java, multiple inheritance concept can only be accomplished through interfaces. I do it using the concept of adapter classes.
interface Dog
{
	public void bark();
}
 
interface Cat
{
	public void meow();
}
 
class DogCat implements Dog,Cat
{
	public void bark()
	{
		System.out.println("Barking");
	}
 
	public void meow()
	{
		System.out.println("Meowww");
	}
}
 
public class Hybrid extends DogCat
{
	public static void main(String[] args)
	{
		Hybrid r =new Hybrid();
		r.bark();
		r.meow();
	}
 
}

AnswerRe: Creating a class that extends more than one class.memberGowtham Gutha15 Nov '12 - 6:59 
Multiple inheritance for classes is however not supported by Java unfortunately. It is limited for interfaces only. Alternatively, you can use multi level inheritance that gets the same as the features of the multiple ones. Here is a simple trick that you can do to achieve this..
 
Let the super classes be S1,S2
 
class A extends S1
{
 
}
class B extends S2
{
}
class C
{
// write the code here by creating objects for A,B
// This could be good if S1,S2 are abstract and that
// you have implemented the abstract methods in the
// classes A,B. So you can create objects for A,B
// access methods in them (the implemented ones) and // also the normal ones.
}
Gowtham Gutha (http://java-demos.blogspot.com)

QuestionThread namesmemberCsTreval4 Oct '12 - 1:19 
App.java
Thread runnable1 = new Thread(new MyThreadRunnable(), "runnable1");
runnable1.setName(runnable1.getName());
runnable1.start();
MyThreadRunnable.java
public class MyThreadRunnable implements Runnable {
    private String name;
 
    public void setName(String name){
        this.name=name;
    }
 
    public void run() {
        System.out.println("Testing MyThreadRunnable"+" "+name);
    } 
}
 
Why does line 2 of App.java result in a 'null' for the name member of MyThreadRunnable? Is it not so that I just created a new Thread, passed a Runnable to it and gave it a name? Is it not supposed to be so that the name property should carry the value of Thread's getName()?
 
I don't understand.
AnswerRe: Thread namesmemberNagy Vilmos4 Oct '12 - 2:54 
Simply put you are addressing the Thread method not the MyThreadRunnable method. You could change your code thus and it would work as expected:
 
MyThreadRunnable runnable = new MyThreadRunnable();
Thread thread = new Thread(runnable, "runnable1");
runnable.setName(thread.getName());
thread.start();


Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett

AnswerRe: Thread namesmemberGowtham Gutha15 Nov '12 - 7:11 
You've already set the name to the thread in the constructor itself. Why are you again setting the same.
This works fine. It probably will not return null.
 
You'll need to call setName() on MyRunnable object and not on Thread object. By the way, the setName() method in MyRunnable object is not at all a name for the thread. It might be just for printing purposes. Do you want it like that only?
 
Remove runnable1.setName(thread.getName()), try calling the setName() method in the class that you've written (MyRunnable).
 
It should work! Test once.
Gowtham Gutha (http://java-demos.blogspot.com)

Questionget ethernet IP addressmemberhari3013 Oct '12 - 19:30 
I've tired to get exact ethernet ip address.
 
InetAddress ip=InetAddress.getLocalHost();
String iaddr = ip.getHostAddress();
 
It return localhost address only. I need ethernet address only..
 
pls help me..
AnswerRe: get ethernet IP addressmemberTorstenH.3 Oct '12 - 19:58 
You don't need no double post to get an answer:
 
How to get ethernet IP address[^]
regards Torsten
When I'm not working

AnswerRe: get ethernet IP addressmemberjschell4 Oct '12 - 11:44 
hari301 wrote:
I need ethernet address only

 
You need to explain your problem more fully.
 
A TCP connection consists for two ends AND of the connections in between.
 
The fact that two ends connect does NOT mean that meaningful (non-private ip) is available on either end.
 
The fact that two ends connect does NOT mean that one end can recover a meaningful ip for the other end in such a way that it uniquely identifies the other end.
 
And of course connections have nothing to do with domain names.
 
Now some of the above might have something to do with your problem. Or not. But it isn't clear what you think you want (neither here nor your other post.)
QuestionJava Based Websevicegroupashish121693 Oct '12 - 1:55 
Hi,
i want to create a webservice in JAVA...pls share the code.....
AnswerRe: Java Based WebsevicemvpRichard MacCutchan3 Oct '12 - 2:34 
This sort of question is impossible to answer in a technical forum. If you want to create a web service then you need to do some research into the tools that are available to help you. A search with Google will get you started.
One of these days I'm going to think of a really clever signature.

AnswerRe: Java Based WebsevicememberTorstenH.3 Oct '12 - 2:36 
Please at least try to type "Java Webservice Tutorial" @ Google.
It's so easy that I don't even want to post links here - would be a waste to web space.
regards Torsten
When I'm not working

QuestionHow can I change a 8-bit bitmap into a 4-bit/1-bit bitmap?memberKangvampire2 Oct '12 - 22:11 
I have a bitmap, such as lena.bmp, which the number of bits per pixel is 8. How can I change the number of bits per pixel?
QuestionCreating a ThreadmemberCsTreval2 Oct '12 - 8:17 
Consider the following code:
public class MyThread extends Thread {
    @Override
    public void run(){
        System.out.println("Testing thread.");
    }
}
public class App 
{
    public static void main( String[] args )
    {
        MyThread thread = new Thread();
    }
}
 
Why does the syntax checker not accept line 5 in 'App.java' (The one with the MyThread Reference Type)? If MyThread is aThread, then why is it incorrect to create a new Thread out of it? I know I'm supposed to replace it with new MyThread, but why is Thread not allowed? Doesn't 'extend' mean 'inherits all properties etc.'?
AnswerRe: Creating a Threadmemberjschell2 Oct '12 - 8:46 
CsTreval wrote:
If MyThread is aThread, then why is it incorrect to create a new Thread
out of it?

 
Your code is stating that 'Thread' is a 'MyThread' which it isn't.
The correct code would be..
 
Thread thread = new MyThread();
AnswerRe: Creating a ThreadmvpRichard MacCutchan2 Oct '12 - 9:32 
You should be creating the same type as you have declared thus:
        MyThread thread = new MyThread();
One of these days I'm going to think of a really clever signature.

GeneralRe: Creating a ThreadmemberCsTreval2 Oct '12 - 20:53 
Yes, but there is also polymorphism as jschell said: Thread thread = new MyThread. I just got the assignment backwards. To me it is more logical to think of a=b instead b=a.
GeneralRe: Creating a ThreadmemberTorstenH.2 Oct '12 - 23:31 
Thread thread = new MyThread();
 
...works, cause Thread is the parental to MyThread.
Using that leaves you with the basic functionality that is given in Thread (unless you cast Thread to a MyThread, then you'll be able to access the additional functions).
 
You could add additional functionality to any Object when you extend it - which is the basic meaning of extension.
So when initializing the Object you will have to choose the right one - the parental Object does not own the additional methods, does not know them.
You would not be able to access them.

Example:

public class Vehicle{
// some basic functions, not important here
}
 
public class Bus extends Vehicle{
 
  public int getSeatQuantity(){
  // return number of seats
  }
}
 
A vehicle can be anything from a bike up to a race car, truck, even a train.
It's not important for a bicycle or a race car how many seats it has. But it's important for a bus.
 
So when you want a Bus (...and later probably know how much seats are available) you will have to create a Bus and not just a Vehicle.
Simple said: it's more specific.
regards Torsten
When I'm not working

AnswerRe: Creating a ThreadmemberPeter_in_27802 Oct '12 - 22:05 
You've got the idea now, but consider this as another way of looking at it:
a MyThread is a Thread and then some. If you had added extra class members - code or data - in the definition of MyThread, it would have stood out like the proverbial.
Another clue is in Java's use of the keyword extends.
 
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012

AnswerRe: Creating a ThreadmemberGowtham Gutha15 Nov '12 - 7:15 
A super class reference variable has the capability to hold its sub class object but a sub class does not have that capability.
 
As MyThread is subclass of Thread, you can write
 
Thread t=new MyThread();
 
But not
 
MyThread m=new Thread();
 
That's false.
Gowtham Gutha (Java-Demos.Blogspot.com)
 

Questionpure java based code needed to read shedule and send an smsmemberask.sagaram2 Oct '12 - 7:08 
Hi! every body i am very new to this and i need an help to start implementation of my idea
 
i need an application that has to the following things
1.it has to store all messages that came to my mobile
 
2.store them in a database the msg contains a mobilenumber date time and msg text
 
3.shedule and send them to that number at that time and date given in msg through my mobile number
please help if it possible any one has a solution
sagaram

AnswerRe: pure java based code needed to read shedule and send an smsmemberjschell2 Oct '12 - 8:50 
Nothing that would make it implicitly impossible although running a database on a mobile without qualifying both of those is unlikely to be generally true.
 

ask.sagaram wrote:
any one has a solution

 
Solution
1. Investigate mobiles
2. Investigate databases on those mobiles
3. Pick a mobile and database (from 1 and 2)
4. Learn how to code database code on a mobile
5. Learn how java networking works and probably networking in general
6. Learn how SMS works.
7. Learn how SMS works on a mobile (which probably goes back to 1.)
8. Write code to do SMS for the mobile.
9. Combine all of the above into an application.
GeneralRe: pure java based code needed to read shedule and send an smsmemberask.sagaram3 Oct '12 - 7:53 
thanks for reply

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   


Advertise | Privacy | Mobile
Web04 | 2.6.130523.1 | Last Updated 25 May 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid