 |
 |
Index ‹ java-programmer
|
- Previous
- 1
- tomcat error 500...Hello all, i am trying to load a class file into a JSP page and getting
a few errors...what ive got is a simple form, that reads a username,
password, and submits it to a login.jsp file. my login.jsp looks
like:
<%@ page import="IMASOS.UserInterface" %>
<html><head> ... <body>
<%
String uname=request.getParameter("username");
String passw=request.getParameter("password");
UserInterface ui = new UserInterface();
boolean success = ui.login(uname,passw);
if (success) out.println("<h2>User logged in</h2>");
else out.println("<h2>Login Failure</h2>");
%>
</body>
and the error im getting is...
exception
org.apache.jasper.JasperException
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:370)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
java.lang.NullPointerException
IMASOS.UserInterface.login(UserInterface.java:92)
org.apache.jsp.login_jsp._jspService(org.apache.jsp.login_jsp:50)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
- 1
- status bar ticking forwardHi,
I am using a servlet application which when I call up a certain page,
the status bar just keeps on ticking forward, you know the progress
bar at the bottom of the screen.
This is happening only on one page. I am doing nothing differnt to
this page that I think would cause this. Any ideas?
Thanks.
TP
- 1
- Third tapestry tutorial availableHi all,
Tapestry is a web app framework (Java) that allows
your web designers to create and edit web pages using
a WYSIWYG editor (DreamWeaver, FrontPage or etc),
while your programmers can still add dynamic contents
to the pages.
I've created my third Tapestry tutorial. You're welcome
to read it
at http://www2.cpttm.org.mo/cyberlab/softdev/tapestry/
Thanks!
- 3
- finding total number of bytes an object takes upGiven an object of a Java class, is there some straightforward way to
find out how many bytes of memory it takes up?
In C there exists a <sizeof()> operator, but even if it had a counter-
part in Java (which doesn't appear to be the case) that wouldn't be
exactly what I want because the objects I want to know the sizes of
contain references to objects of other classes, and I need to know the
_total_ bytes taken up by that object, its components, its components'
components, and so on. Can anybody point me to how I can find this
out? Any information would be greatly appreciated.
---Kevin Simonson
"You'll never get to heaven, or even to LA,
if you don't believe there's a way."
from _Why Not_
- 5
- 5
- More on exceptionsHi,
I am looking at the following code. If an UnsupportedEncodingException
is thrown in getDD() how will that be handled by the code. Am I
missing something? what is good practice?
cheers,
//mike
public void myMethod {
try {
incomingDialog.sendStatus(dialog.getDD());
} catch (IOException e) {
logger.severe(e.getMessage());
throw new ScenarioException(Reason.NETWORKERROR, e);
}
}
The code above will call this code:
protected Object getDD() {
if (dd == null) {
try {
this.dd = invite.getContent();
} catch (UnsupportedEncodingException e) {
logger.severe(e.getMessage());
throw new ScenarioException(Reason.MIMEERROR, e);
} catch (IOException e) {
logger.severe(e.getMessage());
throw new ScenarioException(Reason.NETWORKERROR, e);
}
}
return dd;
}
- 5
- jsp page giving error on tomcat 5Hi
i have written a class for database connection. It has two public
functions connect() which return an object of class Connection and
function close which close the connection
I am using that class in a jsp page to connect to database, but I am
getting an error :
Generated servlet error:
[javac] Compiling 1 source file
/usr/tomcat/work/Catalina/localhost/tpr/org/apache/jsp/web/jsp/index_jsp.java:7:
package db does not exist
import db.*;
^
/usr/tomcat/work/Catalina/localhost/tpr/org/apache/jsp/web/jsp/index_jsp.java:51:
cannot resolve symbol
symbol : variable ibDriverTest
location: class org.apache.jsp.web.jsp.index_jsp
Connection con = ibDriverTest.connect();
......
The class is in the package db. Can you please tell why is import db.*
not working.
Thanks is advance
Lalit
- 5
- XML Processing Approaches with JavaWhen I want to manipulate and retrieve data from XML file,
I used to use DOM or SAX, and this is JAXP API from Sun.
Some people told me I should use XPath instead, since it's easier for coding.
But we need to use apache's xalan library.
What do u think? please advise. thanks!!
- 6
- Problems to calculate sinI must create a program that use trigonometry function.
I know sin(30)=0.5 but when I use Math.sin() I can't get it
Math.sin(30*Math.PI/180)=0.49999999999999994
What's the problem?
Thank you
Stefano Buscherini
- 7
- What's the point?Here's some thoughts from a Java guy at JavaOne:
http://beust.com/weblog/archives/000388.html
As JavaOne 2006 opens its doors today, the age-old question is bound
to be asked again and again: will Sun open source Java?
I have a fairly straightforward answer: I don't care.
And I suppose that most of the Java developers out there don't care
either.
What exactly is not open source in the Java we use today? I had to
think hard to answer this question because, frankly, everything I need
on a daily
basis is already available in source form, with one exception: the
Java Virtual Machine.
Sun's JVM (and others) is admittedly very good and I'm sure a lot of
developers would be interested in knowing how it works, but let's face
it: the inner workings of a Java Virtual Machine are completely
irrelevant to
most Java developers and not having access to this resource will
probably
never get in the way of writing Java code.
With that in mind, why is the question of open sourcing coming back so
often?
One word: zealotry.
*Posted from the Opera Mini Java browser on my Nokia 9300.
- 7
- how change from down to up to up to downHello
sorry for my englisch :-(
Who kan help my.
This is a java bubbles from te bottem tot go's high.
I want to make snow, so the must go from high tot te bottem.
what can i change in the java
thanks for help :-)
<html>
<head>
<meta http-equiv="Content-Language" content="nl">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title></title>
<meta name="Microsoft Theme" content="arcs 111, default">
<meta name="Microsoft Border" content="tl, default">
</head>
<body background= bgcolor="#FFFFCC" text="#000000" link="#3399FF"
vlink="#999933" alink="#FF9900">
<!--mstheme--><font face="Verdana, Arial, Helvetica">
<p>
<script language="JavaScript"><!--
MSFPhover =
(((navigator.appName == "Netscape") &&
(parseInt(navigator.appVersion) >= 3 )) ||
((navigator.appName == "Microsoft Internet Explorer") &&
(parseInt(navigator.appVersion) >= 4 )));
function MSFPpreload(img)
{
var a=new Image(); a.src=img; return a;
}
// --></script><script language="JavaScript">
<!--
if(MSFPhover) { MSFPnav1n=MSFPpreload; MSFPnav1h=MSFPpreload; }
// --></script>
<script language="JavaScript1.2">
<!-- Begin
var no = 12; // image number or falling rate
var speed = 2; // the lower the number the faster the image moves
var snow = new Array();
snow[0] = "bubbel.gif"
snow[1] = "bubbel2.gif"
snow[2] = "bubbel3.gif"
var ns4up = (document.layers) ? 1 : 0; // browser sniffer
var ie4up = (document.all) ? 1 : 0;
var ns6up = (document.getElementById&&!document.all) ? 1 : 0;
var dx, xp, yp; // coordinate and position variables
var am, stx, sty; // amplitude and step variables
var i, doc_width = 800, doc_height = 1800;
if (ns4up||ns6up) {
doc_width = self.innerWidth;
doc_height = self.innerHeight;
} else if (ie4up) {
doc_width = document.body.clientWidth;
doc_height = document.body.clientHeight;
}
dx = new Array();
xp = new Array();
yp = new Array();
am = new Array();
stx = new Array();
sty = new Array();
j = 0;
for (i = 0; i < no; ++ i) {
dx[i] = 0; // set coordinate variables
xp[i] = Math.random()*(doc_width-50); // set position variables
yp[i] = Math.random()*doc_height;
am[i] = Math.random()*20; // set amplitude variables
stx[i] = 0.02 + Math.random()/10; // set step variables
sty[i] = 0.7 + Math.random(); // set step variables
if (ns4up) { // set layers
if (i == 0) {
document.write("<layer name=\"dot"+ i +"\"
left=\"15\" top=\"15\" visibility=\"show\"><img src=\""+ snow[j] + "\"
border=\"0\"></layer>");
} else {
document.write("<layer name=\"dot"+ i +"\"
left=\"15\" top=\"15\" visibility=\"show\"><img src=\""+ snow[j] + "\"
border=\"0\"></layer>");
} } else if (ie4up||ns6up) { if (i ==
0)
{
document.write("<div id=\"dot"+ i +"\"
style=\"POSITION: absolute; Z-INDEX: "+ i +"VISIBILITY: visible; TOP: 15px;
LEFT: 15px; width:1;\"><img src=\"" + snow[j] + "\" border=\"0\"></div>");
} else {
document.write("<div id=\"dot"+ i +"\"
style=\"POSITION: absolute; Z-INDEX: "+ i +"VISIBILITY: visible; TOP: 15px;
LEFT: 15px; width:1;\"><img src=\"" + snow[j] + "\" border=\"0\"></div>");
}
}
if (j == (snow.length-1)) { j = 0; } else { j += 1; }
}
function snowNS() { // Netscape main animation function
for (i = 0; i < no; ++ i) { // iterate for every dot
yp[i] -= sty[i]; if (yp[i] < -50) {
xp[i] = Math.random()*(doc_width-am[i]-30);
yp[i] = doc_height;
stx[i] = 0.02 + Math.random()/10;
sty[i] = 0.7 + Math.random();
doc_width = self.innerWidth;
doc_height = self.innerHeight; }
dx[i] += stx[i];
document.layers["dot"+i].top = yp[i]+pageYOffset;
document.layers["dot"+i].left = xp[i] +
am[i]*Math.sin(dx[i]);
}
setTimeout("snowNS()", speed);
}
function snowIE_NS6() { // IE main animation function
for (i = 0; i < no; ++ i) { // iterate for every dot
yp[i] -= sty[i];
if (yp[i] < -50) {
xp[i] = Math.random()*(doc_width-am[i]-30);
yp[i] = doc_height;
stx[i] = 0.02 + Math.random()/10;
sty[i] = 0.7 + Math.random();
doc_width =
ns6up?window.innerWidth-5:document.body.clientWidth;
doc_height =
ns6up?window.innerHeight-5:document.body.clientHeight;
}
dx[i] += stx[i];
if (ie4up){
document.all["dot"+i].style.pixelTop =
yp[i]+document.body.scrollTop;
document.all["dot"+i].style.pixelLeft = xp[i] +
am[i]*Math.sin(dx[i]);
}
else if (ns6up){
document.getElementById("dot"+i).style.top=yp[i]+pageYOffset;
document.getElementById("dot"+i).style.left=xp[i] +
am[i]*Math.sin(dx[i]);
}
}
setTimeout("snowIE_NS6()", speed);
}
if (ns4up) {
snowNS();
} else if (ie4up||ns6up) {
snowIE_NS6();
}
// End -->
</script>
<!--mstheme--></font>
</html>
- 8
- problem with ListIteratorHello,
I've read about the listiterator. It allows me to traverse the list in
either direction and modify the list during iteration.
But I've tried to add list elements during the iteration and got the
error message.
-- java.util.ConcurrentModificationException
at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:444)
at java.util.AbstractList$Itr.next(AbstractList.java:421)
Is it possible to add the new elements at the end of the list??
Thanks
Lucia
- 8
- OT- interesting article in the NY TimesNew York Times
http://www.nytimes.com/2004/01/26/opinion/26HERB.html
----------------------------------------------------------------------
----------
January 26, 2004
OP-ED COLUMNIST
Education Is No Protection
By BOB HERBERT
The conference was held discreetly in the Westin New York hotel in
Times Square last week, and by most accounts it was a great success.
The main objections came from a handful of protesters who stood
outside in a brutally cold wind waving signs that said things
like "Stop Sending Jobs Overseas" and "Put America Back to Work." No
one paid them much attention.
The conference was titled "Offshore Outsourcing: Making the Journey
Work for Your Corporation." Its goal was to bring executives up to
speed on the hot new thing in corporate America, the shipment of
higher-paying white-collar jobs to countries with eager, well-
educated and much lower-paid workers.
"We basically help companies figure out how to offshore I.T.
[information technology] and B.P. [business process functions]," said
Atul Vashistha, the chief executive of NeoIT, a California consulting
firm that co-hosted the conference.
Several big-name corporations had representatives at the conference,
including Procter & Gamble, Motorola, Cisco Systems and Gateway.
Because the outsourcing of white-collar jobs is so controversial and
politically charged (especially in a presidential election year),
there was a marked reluctance among many of the participants to speak
publicly about it. But Mr. Vashistha showed no reluctance. He was
quick to proselytize.
"These companies understand very clearly that this is a very painful
process for their employees and for American jobs in the short term,"
he said. "But they also recognize that if they don't do this, they
will lose more jobs in the future and they won't have an ability to
grow in the future."
He said his firm had helped clients ship about a billion dollars'
worth of projects offshore last year.
Noting that he is an American citizen who was born in India, Mr.
Vashistha said he is convinced that outsourcing will prove to be a
long-term boon to the U.S. economy as well as the economies of the
countries acquiring the exported jobs.
Whether it becomes a boon to the U.S. economy or not, the trend
toward upscale outsourcing is a fact, and it is accelerating. In an
important interview with The San Jose Mercury News last month, the
chief executive of Intel, Craig Barrett, talked about the integration
of India, China and Russia ?with a combined population approaching
three billion ?into the world's economic infrastructure.
"I don't think this has been fully understood by the United States,"
said Mr. Barrett. "If you look at India, China and Russia, they all
have strong education heritages. Even if you discount 90 percent of
the people there as uneducated farmers, you still end up with about
300 million people who are educated. That's bigger than the U.S. work
force."
He said: "The big change today from what's happened over the last 30
years is that it's no longer just low-cost labor that you are looking
at. It's well-educated labor that can do effectively any job that can
be done in the United States."
In Mr. Barrett's view, "Unless you are a plumber, or perhaps a
newspaper reporter, or one of these jobs which is geographically
situated, you can be anywhere in the world and do just about any job."
You want a national security issue? Trust me, this threat to the long-
term U.S. economy is a big one. Why it's not a thunderous issue in
the presidential campaign is beyond me.
Intel has its headquarters in Silicon Valley. A Mercury News
interviewer asked Mr. Barrett what the Valley will look like in three
years. Mr. Barrett said the prospects for job growth were not
good. "Companies can still form in Silicon Valley and be competitive
around the world," he said. "It's just that they are not going to
create jobs in Silicon Valley."
He was then asked, "Aren't we talking about an entire generation of
lowered expectations in the United States for what an individual
entering the job market will be facing?"
"It's tough to come to another conclusion than that," said Mr.
Barrett. "If you see this increased competition for jobs, the
immediate response to competition is lower prices and that's lower
wage rates."
We can grapple with this problem now, and try to develop workable
solutions. Or we can ignore this fire in the basement of the national
economy until it rages out of our control.
E-mail: email***@***.com
- 8
- 9
- JDK 1.5 metadata feature docs?Hi all,
Has anyone come across documentation that thoroughly describes metadata
functionality that will be available in JDK 1.5? I only saw some brief
examples of what it's supposed to do, and I downloaded JDK, but I can't find
any docs. Any pointers?
|
| Author |
Message |
Jeff Higgins

|
Posted: 2007-9-9 5:54:00 |
Top |
java-programmer, 3D surface plot
timothy ma and constance lee wrote:
> Anyone know anysite teaching 3D mesh plot? Like z = x^2 + y^2
>
<http://www.developer.com/java/other/article.php/3508706>
|
| |
|
| |
 |
Roedy Green

|
Posted: 2007-9-9 17:11:00 |
Top |
java-programmer >> 3D surface plot
On Sat, 08 Sep 2007 21:36:32 GMT, "timothy ma and constance lee"
<email***@***.com> wrote, quoted or indirectly quoted someone who said
:
>Anyone know anysite teaching 3D mesh plot? Like z = x^2 + y^2
Have a look at how I did them at
http://mindprod.com/jgloss/modulus.html
I used the wavelength function to map the Z value onto a colour.
See http://mindprod.com/products2.html#WAVELENGTH
for a more traditional map, see http://mindprod.com/jgloss/graph.html
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
|
| |
|
| |
 |
timothy ma and constance lee

|
Posted: 2007-9-10 9:44:00 |
Top |
java-programmer >> 3D surface plot
Roedy
Thank but i want to have something plot simliar to a grid 3D plot.
Please help
"Roedy Green" <email***@***.com> wrote in message
news:email***@***.com...
> On Sat, 08 Sep 2007 21:36:32 GMT, "timothy ma and constance lee"
> <email***@***.com> wrote, quoted or indirectly quoted someone who said
> :
>
>>Anyone know anysite teaching 3D mesh plot? Like z = x^2 + y^2
>
> Have a look at how I did them at
> http://mindprod.com/jgloss/modulus.html
>
> I used the wavelength function to map the Z value onto a colour.
>
> See http://mindprod.com/products2.html#WAVELENGTH
>
> for a more traditional map, see http://mindprod.com/jgloss/graph.html
> --
> Roedy Green Canadian Mind Products
> The Java Glossary
> http://mindprod.com
|
| |
|
| |
 |
| |
 |
Index ‹ java-programmer |
- Next
- 1
- Setter method in form bean corresponding to text field in JSPhi all,
In my JSP, I am having a text field like this
<input type="text" name="data(id)" />
Please note, that I am not using <html:text> tag. Can you tell me what
should be the corresponding setter nethod signature in the bean.
I have tried
public void setData(String key, String value) and
public void setData(String key, Object value)
but both of them are not working.
I have also noted that if I use <html:text> tag in the same mannar,
then my {Object value} setter method gets called.
Thanks for any help,
- 2
- 3
- Unusual Error Message
I have some Java classes that accept parameters, perform login then
update MYSQL tables. The code runs fine when executed from IDE
(JBuilder). When I try to run it from a JSP I get the following
message. Can't make heads or tails out of it. Does anyone see the
problem? What does the first line mean?
Thanks
javax.servlet.ServletException: Name index 59136 in LocalVariableTable
has bad constant type in class file
com_xyz_practice/CrunchBracketSchedule
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:848)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:781)
org.apache.jsp.brackets20B.bracket_005fauto_005fsch_005fbrks_jsp._jspService(org.apache.jsp.brackets20B.bracket_005fauto_005fsch_005fbrks_jsp:118)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
java.lang.ClassFormatError: Name index 59136 in LocalVariableTable has
bad constant type in class file com_xyz_practice/CrunchBracketSchedule
java.lang.ClassLoader.defineClass1(Native Method)
java.lang.ClassLoader.defineClass(ClassLoader.java:620)
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1629)
org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:850)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1299)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1181)
java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
com_xyz_practice.ScheduleBrackets.Schedule(ScheduleBrackets.java:59)
org.apache.jsp.brackets20B.bracket_005fauto_005fsch_005fbrks_jsp._jspService(org.apache.jsp.brackets20B.bracket_005fauto_005fsch_005fbrks_jsp:92)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
- 4
- Let thread wait till memory is availablehi all,
a basic question:
i have a memory consuming encoding process which runs in its own
thread.
To preseve OutOfMemory errors when a lot of those treads are running,
i want this thread to check the current memory heap, and maybe wait as
long as there's some available.
Is that possible ?
I think this must be a very common problem in thread programming?
Greets,
chris
- 5
- [Advanced Java/Gurus] JNI/Win32 hWnd JDK 1.4.2_05 freeze on Javascript CallbackDear Colleagues,
An advanced Java (i.e.: SUN Java Plugin 1.4.2_05) issue would require
your expertise. Inside a "JRE/1.4.2_05" environment (i.e.: version
prior to that latest installment are performing with an adequate
satisfaction) the execution of an "Applet", acquiring native methods
through a "JNI/Win32" interface and returning data using the
"jaws.jar", (i.e.: JSObject callback to "Javascript") hangs on the
"callback" invocation. (i.e.: it is happening in a "single threaded"
environment)
Please note that the invoked "Java" routine is not returning (i.e.:
the "JavaScript/Jdirect" call happens just before), as well as the
"JavaScript" callback is not being entered.
As remarkable as it could be, to unblock the "Java" runtime main
thread, one would right click on the "Internet Explorer" window (i.e.:
right in the task bar). Consequently the execution of the process
continues.
I have explored numerous options including "Thread" notifications,
garbage collections and method finalizations without success. Finally,
the option of duplication the "hWnd"
based "Win32" messaging flow stood as my ultimate option. I have
finally managed to retrieve the top level "hWnd" handle from my
"JDK1.4.2_05/Win32" environment, not to say easily? and declared
method such as "SendMessage", "SetFocus", "SetEnabled" (i.e.: and so
on) to replicate the behavior of my "right click". Through the "Spy++"
delivered messaged I, unfortunately, had no chance to discover the
message (i.e.: or the sequence) that had unblocked my process.
Please note that these "JNI/Win32" calls are executed inside a
separate thread, which is not blocked by the "main/thread" freeze.
Finally, I am relying on your wisdom and experience to win that quite
complicated case, unless an upcoming release of the "SUN/JRE" would
correct that damned state of things.
Thank you for your time; and please do not hesitate to come back for
details.
- 6
- Capital PunishmentIn the past I had made posts on these programming forums with
references to my website. I have stopped doing that since it is
labelled spamming.
The other day, on one of these forums, an individual threatend to wipe
out my site from the internet because he did't find use for the post.
Which one is a bigger offence. To post a message or to terminate
someone's site.
Asad
- 7
- Java Program error need helpI am working on this program for class and I can't figure out why I am
getting class or interface expected on the last two { symbols. Please
help, I am not trying to cheat, just need a point in the write
direction. Thank you
/*
Author: Kevin Rosier
Course: POS 407
Assignment: Week 3 Mortgage Calculator
Written: Oct 16, 2006
Creates a sales tax calculator with a GUI.
*/
// class names
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
import java.text.*;
import java.util.*;
import javax.*;
public class MortgageCalculatorGUIwk3 extends JFrame implements
ActionListener
{
JFrame mortgageFrame;
JPanel mortgagePanel;
JButton mortgageButton;
JButton clearButton;
JButton exitButton;
JLabel mortgageLabel;
JLabel interestrateLabel;
JLabel yearLabel;
JLabel paymentLabel;
JTextField mortgageField;
JTextField interestrateField;
JTextField yearField;
JTextField paymentField;
public MortgageCalculatorGUIwk3() //constructor
{
{
// defining JFrame
mortgageFrame = new JFrame("Calculate Your Mortgage Payment");
mortgageFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mortgageFrame.setSize(500,500);
//public static void main(String args[]){
ActionListener actionListener = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
AstractionButton aButton = (AbstractButton)
actionEvent.getSource();
boolean selected = abutton.getmodel().isSelected();
System.out.println(actionEvent.getActionCommand()
+ " - selected? " + selected);
}
};
//constructs Radio buttons
JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("Menu");
ButtonGroup buttonGroup = new ButtonGroup();
menu.setMnemonic(KeyEvent.VK_M);
JRaidoButtonMenuItem emptyMenuItem = new
JRadioButtonMenuItem();
empyMenuItem.setActionCommand("Empty");
emptyMenuItem.addActionListener(actionListener);
buttonGroup.add(emptyMenuItem);
menu.add(empyMenuItem);
JRadioButtonMenuItem oneMenuItem = new JRadioButtonMenuItem("7
years at 5.35%");
oneMenuItem.addActionListener(actionListener);
buttonGroup.add(oneMenuItem);
menu.add(oneMenuItem);
JRadioButtonMenuItem twoMenuItem = new JRadioButtonMenuItem("15
years at 5.5%");
twoMenuItem.addActionListener(actionListener);
buttonGroup.add(twoMenuItem);
menu.add(twoMenuItem);
JRadioButtonMenuItem threeMenuItem = new
JRadioButtonMenuItem("30 years 5.75%");
threeMenuItem.addActionListener(actionListener);
buttonGroup.add(threeMenuItem);
menu.add(threeMenuItem);
menuBar.add(menu);
frame.setJMenuBar(menuBar);
frame.setSize(350, 250);
frame.setVisible(true);
// defining JPanel
JPanel mortgagePanel = new JPanel(new GridLayout(7,2,10,30));
// defining contents on the panel
mortgageLabel = new JLabel("Mortgage Amount Desired");
interestrateLabel = new JLabel("Interest Rate Desired");
yearLabel = new JLabel("Years of Mortgage");
paymentLabel = new JLabel("Payment");
mortgageButton = new JButton("Your Monthly Payment Is");
clearButton = new JButton("Reset");
exitButton = new JButton("Exit");
// data for calculations
mortgageField = new JTextField("");
interestrateField = new JTextField("");
yearField = new JTextField("");
paymentField = new JTextField("");
paymentField.setEditable(false);
// Adding components to the GUI
mortgagePanel.add(mortgageLabel);
mortgagePanel.add(mortgageField);
mortgagePanel.add(interestrateLabel);
mortgagePanel.add(interestrateField);
mortgagePanel.add(yearLabel);
mortgagePanel.add(yearField);
mortgagePanel.add(mortgageButton);
mortgagePanel.add(clearButton);
mortgagePanel.add(exitButton);
mortgagePanel.add(paymentLabel);
mortgagePanel.add(paymentField);
mortgageFrame.add(mortgagePanel);
mortgageFrame.setVisible(true);
// action buttons
mortgageButton.addActionListener(this);
clearButton.addActionListener(this);
exitButton.addActionListener(this);
}
} //end constructor
// What action is to be performed
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
if(source == mortgageButton) {
String sMortgage = mortgageField.getText();
String sInterestrate = interestrateField.getText();
String sYear = yearField.getText();
double mortgage = Double.parseDouble(sMortgage);
double interestrate = Double.parseDouble(sInterestrate);
double year = Double.parseDouble(sYear);
double numberOfPayments = year * 12;
double monthlyInterest = interestrate / 100 / 12;
double x = Math.pow(1+monthlyInterest, numberOfPayments);
double monthlyPayment = (mortgage * x * monthlyInterest)/(x-1);
DecimalFormat df = new DecimalFormat("$0,000.00");
paymentField.setText(df.format(monthlyPayment));
}
else if(source == clearButton)
{
mortgageField.setText("");
interestrateField.setText("");
yearField.setText("");
}
else if(source == exitButton)
{
System.exit(0);
}
} // end actionPerformed
public static void main(String [] args) {
MortgageCalculatorGUIwk3 thisCalc = new MortgageCalculatorGUIwk3();
}; //end main
};
} //end class
}
- 8
- can anybody please check this code out?Hi all,
I'm rather inexperienced in Java but I'm in need of defining a
JTable(N,N) with non-editable underdiagonal elements. I do not know if
it's better to do it by using TableModel or directly JTable, but I used
the latter because it looked easier to me.
The following code gives no errors in NetBeans, but using the newborne
UD_JTable class in MATLAB I get a very nasty error which pretty much
looks like some sort of memory allocation fault.
Here is the code:
import javax.swing.*;
import javax.swing.table.*;
public class UD_JTable extends JTable
{
public UD_JTable(int rows, int cols)
{
super();
}
public boolean isCellEditable( int rowIndex , int columnIndex)
{
if(rowIndex > columnIndex)
{
return false;
}
else
{
return true;
}
}
public static void main(String[] args)
{
}
}
And here is the error
??? Java exception occurred:
java.lang.ArrayIndexOutOfBoundsException: 0 >= 0
at java.util.Vector.elementAt(Unknown Source)
at javax.swing.table.DefaultTableColumnModel.getColumn(Unknown Source)
at javax.swing.JTable.convertColumnIndexToModel(Unknown Source)
at javax.swing.JTable.setValueAt(Unknown Source)
.
Does anybody have a clue of what's happening???
Thank you ahead
lor
- 9
- How to display the texts into 2 line in JButton?hi, I am newbies here.
I want to display 2 words in jbutton but if I use setText("Add Record");
When display, it show Add record (in a line)
I want it display as
Add
Record
(2lines)
in jbutton?
How to do that?
- 10
- WaitForMultipleObject feature in JavaCurrent, I have a method, which will perform lock on
void MyWait()
{
CountDownLatch.aWait
// We can have access to the Stop lock.
}
void MyStop()
{
// Signal Stop lock.
}
This works fine until we need to stop the thread from keep waiting on
CountDownLatch, when there is a stop signal. (The method who send stop
signal doesn't have access to CountDownLatch, else, the stop method
can just directly signal the CountDownLatch)
We would like to have something, "if either CountDownLatch is signaled
or Stop lock is signaled", unblock the thread.
Perhaps something like
WaitForMultipleObject(CountDownLatch, StopLock) in method void
MyWait()
either one of the object being signaled, the thread will continue
execution.
May I know how can I do that in Java?
One of the solution is that I can interrupt the Thread which is halted
at line CountDownLatch.aWait. However, I have no access to the Thread
which halted at line CountDownLatch.aWait
- 11
- JSTL - Following MVCHi, I've got a J2EE application (trying) to follow the MVC paradigm.
So far, there is a data model, which is sent to the view. The view
then calls java functions to html formate Strings from this model,
using inline java code, which I don't like very much. Would you:
a) leave it as it is
for: No work to do
against:Mixes JSTL tags with java inline code - ugly
b) add an additional "view-model" attribute for each attribute to be
displayed on the view, that already contains the necessary html style
informations
for: No more logic (java inline code) in the jsps
against: each attribute exists in 2 varieties in one hugh model
c) Add another view-model, and map from data-model to view model in a
huge loop before displaying the view model on the view?
pro: Data-model and view-model are totally separated, no more logic in
the jsps
against: lots of programming to do, and mapping all attributes from
one model to the other model would cost a lot of performance.
d) Simply add new getter methods for each attribute to the current
data-model.
So e.g. there would be a getName() method to get the data
representation of the name, and getFormatedName() which would first
call getName and then manipulate the name attribute to get a view
representation of it.
pro No more logic in the jsps, beans will not be "flooded" by
"duplicate attributes"
contra: Data model would still contain view-model getter methods.
Thanks for your advice,
Christine
- 12
- [OT] Linux Flaw DiscoveredKernel Flaw Makes Linux Crash Easily
A flaw in the Linux kernel allows a 20-line C program to crash most
distributions of the operating system using the 2.4 and 2.6 kernels
running on x86 and x86-64 architectures, according to security
researchers.
http://www.computerworld.com/newsletter/0,4902,93833,00.html?nlid=OS
l8r, Mike N. Christoff
- 13
- problem while regenerating jpg file from swing image.Hi,
I am trying to regenerate the jpg file with the image that is
generated by java swings. But the x,y positions are not matching from
swing generated image to jpg file generated.Any body worked on the
similar problem please suggest.
Thanks in advance.
- 14
- va_list in JNICan anyone tell me if it is possible to call a C function which
contains a va_list parameter from java code. I have a existing library
that I wish to use by creating a Java wrapper around the code.
- 15
- What to use as HashMap Key?Hi. I'm looking for advice on using keys for a HashMap.
Is it typical to just use a string as a key, e.g., "Item A", "Item B",
etc.? Or are other approaches better? Since the key is just an
Object, I thought there might be some other approach commonly used
that is more efficient/effective.
Thanks for any advice!
Ken
|
|
|