|
Hello,
I have a signed applet. a web page (asks for permissions and) loads and the applet and performs some information processing and writes data to a text file.
Then the web page refreshes a few components and gives the applet a different CSS class (to move it to other position on the page) and the applet reloads, reads data from file and must load it as html into JTextPane.
The problem: when the applet reloads it is given a parameter from html code. This way it knows the now it must display the information to the JTextPane as a list of links in html format. But the JTextPane displays nothing.
I tried to load the html as a simple text and it worked. I also tried to run the applet with the parameter to display data from the very start (when webpage asks for permission to run the applet) and it worked.
So in short I the problem is that when the applet initializes and loads data from the start everything is fine but if it first performs inf. processing and then reloads it cant display html in JTextPane.
I am using javax.swing.JApplet; for applet.
This is the initialization of the applet. It starts the applet as a thread.
<pre lang="java">
public void init() {
try {
jbInit();
new Thread(this, "processFunctionThread").start();
</pre>
jbInit() builds/adds visulal components on the applet.
<pre lang="java">
displayEditorPane = new JEditorPane();
displayEditorPane.setContentType("text/html");
displayEditorPane.setEditable(true);
displayEditorPane.addHyperlinkListener(this);
displayEditorPane.setBounds(new Rectangle(10, 10, 260, 365));
displayEditorPane.setContentType("text/html");
dataScrolling = new JScrollPane(displayEditorPane);
dataScrolling.setBounds(new Rectangle(10, 10, 260, 365));
dataScrolling.setVisible(true);</pre>
public void run() has the main function that (depending on the passed from html parameter) performs actions.
<pre lang="java">
if ( getParameter("scan").equals("doscan") ) {
// performs initial information processing
} else if(getParameter("scan").equals("scanresults")) {
// after the web page gives the applet a different css class it reloads and displays data to JTextPane.
}
</pre>
It's the same either with JEditorPane or with JTextPane.
Please, help me! Thanks
|
|
|
|
|
I need to forma network with 4 hosts and 2 routers.How to do that,I need a start from where I can start.And then I have to implement IP and Link layer interfacing and also IP packet fragmentation.If anyone of you can help with anypart of the project.Thank You in advance.
|
|
|
|
|
I don't think anyone can give an answer to such a far reaching question; this is a case for some Google research about networking. BTW what does this have to do with Java?
|
|
|
|
|
csepratik wrote: And then I have to implement IP and Link layer interfacing and also IP packet
fragmentation
Java doesn't do "IP".
It does TCP, UDP and sort of ICMP (but normally good enough.)
|
|
|
|
|
hi how are you all
<b>(SORRY FOR MY BAD ENGLISH)</b>
i have a server (localhost) and want to send pdf file from my servlet on server to the client
how can i do it
thank you very much
|
|
|
|
|
response.setHeader("Content-type","application/pdf");
response.setHeader("Content-Disposition","attachment; filename=\"destination filename\"");
BufferedOutputStream bo=new BufferedOutputStream(response.getOutputStream());
byte buffer[]=new byte[1024];
FileInputStream fis=new FileInputStream("File in server");
while(fis.read(buffer)>0){
bo.write(buffer);
}
fis.close();
bo.close();
|
|
|
|
|
ty very much for help
plz can u tell me how to catch the in the client
|
|
|
|
|
The codes written is used to send back response to client and it is compliant with html...
So you just use the browser, surf to the site with the above code and you will get the file...
|
|
|
|
|
but first i have to catch the file in Client side
have i use Inputstream or what ?
ty for help
|
|
|
|
|
In fact, this question may not be in this forum. Because, it is all about web and html
you can use .... to upload the file ...
and in server side, you can use request.getInputStream().....
or use third party library to handle upload request as ref site:
ref: http://www.andowson.com/posts/list/197.page
modified 12-Oct-11 3:09am.
|
|
|
|
|
But he doesn't want to upload the file from the client to the server. He wants to download the file from the server to the client. Completely the opposite way round from your answer.
|
|
|
|
|
So you need the permission of that client and he/she open a port for you :
java.net.Socket s=new Socket();
s.connect(new InetSocketAddress(InetAddress.getByName(hostname),portNo));
s.getInputStream();
......
Or remote login to that computer, it is depends on what methods that computer use to get the connection.
|
|
|
|
|
Original question from assignment:
3. Write a driver program (where the main() method is) that would utilize all of your classes. The driver class can be in a separate package or in any of the already existing four packages. In the main() method you must:
a. Create various objects from the 6 classes, and display all their information using the toString() method;
b. Test the equality of some to the created objects using the equals() method;
c. Create an array of 10 Vehicule objects and fill that array with various objects from the 6 classes (each class must have at least one entry in that array);
d. Trace that array to find the object that has the cheapest price. Display all information of that object along with its location (index) in the array.
--------------------------------
I can figure out how to use a for loop to figure out the lowest price in the array. We were told to use the accessor method to get the price but how do i get the lowest price.
I have a total of 6 class. but these 2 should be enough to get the idea. and the driver.
Driver:
import java.util.ArrayList;
import Package1.Vehicule;
import Package2.Car;
import Package2.FamilyCar;
import Package2.FamilyCar.CarType;
import Package2.SportsCar;
import Package3.Truck;
import Package3.Truck.TruckType;
import Package4.Bus;
import Package4.Bus.BusType;
public class Driver {
public static void main(String[] args) {
CarType ct = null;
TruckType tt = null;
BusType bt = null;
Vehicule vTest = new Vehicule("Hybrid", 1.9, 12000);
System.out.println(vTest);
Vehicule vvTest = new Vehicule("Hybrid", 1.9, 12000);
System.out.println(vvTest);
Car cTest = new Car("Honda", "Civic", 2009, "Unleaded", 2.8, 13000);
System.out.println(cTest);
FamilyCar fTest = new FamilyCar(7, ct.Sedan, "Honda", "Odessey",
2009, "Unleaded", 2.8, 13000);
System.out.println(fTest);
SportsCar sTest = new SportsCar(false, 250, "Mazda", "Rx8", 2004,
"Unleaded", 1.5, 15000);
System.out.println(sTest);
Truck tTest = new Truck(tt.Tank, "Diesel", 1.2, 10000);
System.out.println(tTest);
Bus bTest = new Bus(bt.city, "Hybrid", 1.9, 12000);
System.out.println(bTest);
System.out.println(vTest.equals(vvTest));
System.out.println(vTest.equals(bTest));
Vehicule[] vehicules = new Vehicule[10];
vehicules[0] = cTest;
vehicules[1] = vTest;
vehicules[2] = tTest;
vehicules[3] = cTest;
vehicules[4] = cTest;
vehicules[5] = cTest;
vehicules[6] = cTest;
vehicules[7] = cTest;
vehicules[8] = bTest;
vehicules[9] = cTest;
int fin = 0;
int ii = 1;
for (int i = 0; i<10; i++, ii++)
{
for (;vehicules[i].getPrice() < vehicules[ii].getPrice();)
fin = i;
}
}
}
Vehicule class:
package Package1;
public class Vehicule {
protected String fuelT;
protected double consum;
protected int price;
public Vehicule ()
{
fuelT = "";
consum = 0.0;
price = 0;
}
public Vehicule(String f, double c, int p)
{
this.fuelT = f;
this.consum = c;
this.price = p;
}
public String toString()
{
return "This Vehicule is a " + fuelT
+ ", consumes " + consum + "liters/100km and costs $"
+ price + ".";
}
public String getFuelT() {
return this.fuelT;
}
public double getConsum() {
return this.consum;
}
public int getPrice() {
return this.price;
}
public void setFuelT(String f) {
this.fuelT = f;
}
public void setConsum(double c) {
this.consum = c;
}
public void setPrice(int p) {
this.price = p;
}
public boolean equals(Vehicule e)
{
boolean ans;
if(this.fuelT == e.fuelT &&
this.consum == e.consum &&
this.price == e.price ){
ans = true;
}
else
ans = false;
return ans;
}
}
Car class:
package Package2;
import Package1.Vehicule;
public class Car extends Vehicule {
String carBrand;
String carMake;
int year;
public Car()
{
super();
carBrand = "";
carMake = "";
year = 0;
}
public Car(String b, String m, int y, String f, double c, int p)
{
super (f,c,p);
this.carBrand = b;
this.carMake = m;
this.year = y;
}
public String toString()
{
return "This Car is a " + fuelT
+ ", consumes " + consum + "liters/100km and costs $"
+ price + ". It is a " + year + " " + carBrand
+ " " + carMake + ".";
}
public String getCarBrand() {
return this.carBrand;
}
public String getCarMake() {
return this.carMake;
}
public int getYear() {
return this.year;
}
public void setCarBrand(String b) {
this.carBrand = b;
}
public void setCarMake(String m) {
this.carMake = m;
}
public void setYear(int y) {
this.year = y;
}
public boolean equals(Car e)
{
boolean ans;
if(this.fuelT == e.fuelT &&
this.consum == e.consum &&
this.price == e.price &&
this.carBrand == e.carBrand &&
this.carMake == e.carMake &&
this.year == e.year){
ans = true;
}
else
ans = false;
return ans;
}
}
|
|
|
|
|
If you can find the lowest price in the array you have satisfied your requirements. Or perhaps your question needs to be clarified.
|
|
|
|
|
Don't take this the wrong way, but are you planning to post all your course work on here for the entire school year? You won't learn too much if you keep saying, "I don't understand this, will you do it for me" every time the teacher sets you a problem.
|
|
|
|
|
We've just had a decleration from up high that our standard programming language should be Java. But no more details than that
Currently we have a large number of Access 97 databases and visual basic 6 apps, that we were planning to migrate to .NET and SQL Server, with future plans to make it ASP.NET.
From previous research it seems that Java is little less organised, there being a number of IDE's/UI widgets/test frameworks etc. I was wondering if anybody can give me pointers on what the leaders are...if you had a greenfield java site, which tools etc would you recommend?
|
|
|
|
|
sounds like you have no Java experience - so WHY do you want to switch to Java?
regards Torsten
I never finish anyth...
|
|
|
|
|
Read the post. OP doesn't, management does.
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
|
|
|
|
|
Are you in a position to question this choice? If you are a Microsoft house, it may be better to stay that way unless there is good reason. Jumping from VB6 is a good start anyway. Whatever the new language used, a complete re-write is a better choice. That way you can work around bad decisions, there always are, made in the original system.
As for Java IDE's, it really is your choice. The two most popular are Netbeans and Eclipse, and I'd choose one of them. My personal recomendation is Netbeans but that is because I use it and am familiar with the way it works.
Have a look at the Java tutorials on oracle.com. Then buy some books and put them on expenses.
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
|
|
|
|
|
I have to say that moving from VB6 to Java seems like an unusual choice, VB.NET or C# seems like a more natural progression, but I guess there is a reason in there somewhere. Maybe the idea is to make the server-side platform independent?
"Less organised" could also be read as "more choice" and I think that is your problem: you will find yourself overwhelmed with choice. I can list the leading frameworks in the various areas, but I can't recommend any in particular because I have no idea what sort of application you are building or what your requirements are. So I'm not going to say that any one is better than the others.
For the web front end you could either look at something like GWT or ZK, or something like SpringMVC or Wicket. There are other frameworks like Seam or Grails that may get you started quicker, but I'm not sure how widely used they are in the real world. JSF might seem a little complicated for someone new to the Java world, but it is part of the JEE standard so should be on the list to consider. And of course, you could always just roll your own with JSPs and servlets.
For the data access layer, you could look at EJB, JPA (without EJB), Hibernate, MyBatis, or straight JDBC (lots of people still do this despite the fact that ORMs get so much press).
Spring is very popular in the Java world (although a significant minority are against it for various reasons). I would at least consider it, and look beyond the Dependency Injection features to see what else it might give you. If you want DI but don't like Spring, take a look at Guice.
In terms of IDEs, the big three are Eclipse, NetBeans and IntelliJ. Various people will argue strongly for their own personal favourite, but the truth is that they're all pretty much on a level these days and it's just a matter of taste as to which you prefer.
Test frameworks: JUnit is almost universal and could be considered a de facto standard in the Java world. Some people use NGTest (which does have some nicer features than JUnit) but is less common so I would stick with JUnit simply because every Java programmer you ever hire will have heard of it.
Then there are some build tools that you should at least look at: Maven vs. Ant, Hudson/Jenkins vs. Continuum.
|
|
|
|
|
Thanks for all these replies they are helpful.
We were going down the .NET route, for the extact reasons pointed out, its new but its more familiar as well And we are questioning this decision, we're a satellite office and pretty self contained, so not following the main mass isn't that usual...we have seperate dev and test domains, they dont for example.
We currently support a large number of Access 97 databases run across teams! And afaik Java (like .NET) has no equivelent (SQL Compact is local install only, and everything else needs servers) The VB6 progs are a little easier, mainly they are front-ends to SQL Server databases.
|
|
|
|
|
cjb110 wrote: We currently support a large number of Access 97 databases run across teams!
Meaning multiple users (multiple applications) accessing a single database?
I have seen reports that this isn't a good idea. I haven't seen anyone suggest that language choice mattered with that either.
cjb110 wrote: And afaik Java (like .NET) has no equivelent (SQL Compact is local install only, and everything else needs servers)
Huh? No equivalent to what exactly? You can use MS Access from java if that is what you are asking.
And you can certainly use SQL Server as well. The type of SQL Server has nothing to do with it. Although if you wanted a single user embedded database then you could use Derby.
|
|
|
|
|
cjb110 wrote: And afaik Java (like .NET) has no equivelent (SQL Compact is local install only, and everything else needs servers)
I have absolutely no idea what that means. Java can use local (embedded) databases, or it can talk to databases located on a central server. Is that what you mean?
|
|
|
|
|
cjb110 wrote: From previous research it seems that Java is little less organised, there being a number of IDE's/UI widgets/test
Choice/options != "less organized".
Far as I can tell frameworks are also better. There is a reason things like nant, log4net, nunit, nHibernate and Spring.net exist. Because they all existed in java first. (And far as I am concerned there are no good logging options in .Net because log4net does not have a large participant base or maybe even no participant base.)
And I certainly haven't seen anything that I would say is comparable to the JEE servers in .Net land. IIS just doesn't seem comparable.
|
|
|
|
|
Question asks:
For each of the classes you must include at least the following methods: accessors, mutators, toString(), equals(). The last 2 methods are always being overrriden.
The toString() method must display clear descriptions and complete information of the object. For example This Family Car is a hybrid, consumes 9.2 liters/100km and costs $25000. It is a 1998 Toyota Camry. It is a sedan which can accommodate 5 passengers.
The equals() method returns true if all attributes of the compared objects are the same values; false otherwise.
These are a few of my 6 classes and a driver. I don't get it how to check the attributes. I can check one but i am not sure how to check it the way it is required by the question.
Vehicule class
package Package1;
public class Vehicule {
protected String fuelT;
protected double consum;
protected int price;
public Vehicule ()
{
fuelT = "";
consum = 0.0;
price = 0;
}
public Vehicule(String f, double c, int p)
{
this.fuelT = f;
this.consum = c;
this.price = p;
}
public String toString()
{
return "This Vehicule is a " + fuelT
+ ", consumes " + consum + "liters/100km and costs $"
+ price + ".";
}
public String getfuel()
{
return fuelT;
}
public boolean equals(Vehicule e)
{
boolean ans;
if(this.fuelT == e.fuelT )
ans = true;
else
ans = false;
return ans;
}
}
Car Class
package Package2;
import Package1.Vehicule;
public class Car extends Vehicule {
protected String carBrand;
protected String carMake;
protected int year;
public Car()
{
super();
carBrand = "";
carMake = "";
year = 0;
}
public Car(String b, String m, int y, String f, double c, int p)
{
super (f,c,p);
this.carBrand = b;
this.carMake = m;
this.year = y;
}
public String toString()
{
return "This Car is a " + fuelT
+ ", consumes " + consum + "liters/100km and costs $"
+ price + ". It is a " + year + " " + carBrand
+ " " + carMake + ".";
}
}
FamilyCar:
package Package2;
public class FamilyCar extends Car{
public enum CarType {Sedan, Van, Suv};
private int maxPass;
private CarType value;
public FamilyCar ()
{
super();
maxPass = 0;
value = null;
}
public FamilyCar (int mp, CarType value, String b,
String m, int y, String f, double c, int p)
{
super(b,m,y,f,c,p);
this.maxPass = mp;
this.value = value;
}
public String toString()
{
return "This Family Car is a " + fuelT
+ ", consumes " + consum + "liters/100km and costs $"
+ price + ". It is a " + year + " " + carBrand
+ " " + carMake + ". It is a " + value + " which can accommodate "
+ maxPass + " passengers.";
}
}
Driver Class:
import Package1.Vehicule;
import Package2.Car;
import Package2.FamilyCar;
import Package2.FamilyCar.CarType;
import Package2.SportsCar;
import Package3.Truck;
import Package3.Truck.TruckType;
import Package4.Bus;
import Package4.Bus.BusType;
public class Driver {
public static void main(String[] args) {
CarType ct = null;
TruckType tt = null;
BusType bt = null;
Vehicule vTest = new Vehicule("Hybrid", 1.9, 12000);
System.out.println(vTest);
Car cTest = new Car("Honda", "Civic", 2009, "Unleaded", 2.8, 13000);
System.out.println(cTest);
FamilyCar fTest = new FamilyCar(7, ct.Sedan, "Honda", "Odessey",
2009, "Unleaded", 2.8, 13000);
System.out.println(fTest);
SportsCar sTest = new SportsCar(false, 250, "Mazda", "Rx8", 2004,
"Unleaded", 1.5, 15000);
System.out.println(sTest);
Truck tTest = new Truck(tt.Tank, "Diesel", 1.2, 10000);
System.out.println(tTest);
Bus bTest = new Bus(bt.city, "Hybrid", 4.0, 25000);
System.out.println(bTest);
System.out.println(vTest.equals(fTest));
}
}
|
|
|
|
|