473,569 Members | 2,747 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Here's one that should be a piece of cake for you java masters :)

23 New Member
I have this program right now, but I need to modify it to output to the JTextPane.
What I mean is, when someone clicks on the 1 button, it needs to output to the TextArea a 1. None of the add, subtract, multiply, divide symbols need to....just the numbers and the decimal point. I have no idea how to do this. Can anyone help me? Here's the program.

/*
* Calculator.java
*
* Created on December 12, 2006, 10:00 PM
* Created by Ken Garlitz
*/

/**
*
* @author Erekose
*/
public class Calculator extends javax.swing.JFr ame {

/** Creates new form Calculator */
public Calculator() {
initComponents( );
}

/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="c ollapsed" desc=" Generated Code ">
private void initComponents( ) {
jScrollPane1 = new javax.swing.JSc rollPane();
jTextPane1 = new javax.swing.JTe xtPane();
jButton1 = new javax.swing.JBu tton();
jButton2 = new javax.swing.JBu tton();
jButton3 = new javax.swing.JBu tton();
jButton4 = new javax.swing.JBu tton();
jButton5 = new javax.swing.JBu tton();
jButton6 = new javax.swing.JBu tton();
jButton7 = new javax.swing.JBu tton();
jButton8 = new javax.swing.JBu tton();
jButton9 = new javax.swing.JBu tton();
jButton10 = new javax.swing.JBu tton();
jButton11 = new javax.swing.JBu tton();
jButton12 = new javax.swing.JBu tton();
jButton13 = new javax.swing.JBu tton();
jButton14 = new javax.swing.JBu tton();
jButton15 = new javax.swing.JBu tton();
jButton16 = new javax.swing.JBu tton();

setDefaultClose Operation(javax .swing.WindowCo nstants.EXIT_ON _CLOSE);
jScrollPane1.se tViewportView(j TextPane1);

jButton1.setFon t(new java.awt.Font(" Tahoma", 1, 12));
jButton1.setTex t("7");

jButton2.setFon t(new java.awt.Font(" Tahoma", 1, 12));
jButton2.setTex t("8");

jButton3.setFon t(new java.awt.Font(" Tahoma", 1, 12));
jButton3.setTex t("9");

jButton4.setFon t(new java.awt.Font(" Tahoma", 1, 12));
jButton4.setTex t("/");

jButton5.setFon t(new java.awt.Font(" Tahoma", 1, 12));
jButton5.setTex t("4");

jButton6.setFon t(new java.awt.Font(" Tahoma", 1, 12));
jButton6.setTex t("5");

jButton7.setFon t(new java.awt.Font(" Tahoma", 1, 12));
jButton7.setTex t("6");

jButton8.setFon t(new java.awt.Font(" Tahoma", 1, 12));
jButton8.setTex t("*");

jButton9.setFon t(new java.awt.Font(" Tahoma", 1, 12));
jButton9.setTex t("1");

jButton10.setFo nt(new java.awt.Font(" Tahoma", 1, 12));
jButton10.setTe xt("2");

jButton11.setFo nt(new java.awt.Font(" Tahoma", 1, 12));
jButton11.setTe xt("3");

jButton12.setFo nt(new java.awt.Font(" Tahoma", 1, 12));
jButton12.setTe xt("-");

jButton13.setFo nt(new java.awt.Font(" Tahoma", 1, 12));
jButton13.setTe xt("0");
jButton13.addAc tionListener(ne w java.awt.event. ActionListener( ) {
public void actionPerformed (java.awt.event .ActionEvent evt) {
jButton13Action Performed(evt);
}
});
jButton13.addKe yListener(new java.awt.event. KeyAdapter() {
public void keyPressed(java .awt.event.KeyE vent evt) {
jButton13KeyPre ssed(evt);
}
});

jButton14.setFo nt(new java.awt.Font(" Tahoma", 1, 12));
jButton14.setTe xt(".");

jButton15.setFo nt(new java.awt.Font(" Tahoma", 1, 12));
jButton15.setTe xt("=");

jButton16.setFo nt(new java.awt.Font(" Tahoma", 1, 12));
jButton16.setTe xt("+");

org.jdesktop.la yout.GroupLayou t layout = new org.jdesktop.la yout.GroupLayou t(getContentPan e());
getContentPane( ).setLayout(lay out);
layout.setHoriz ontalGroup(
layout.createPa rallelGroup(org .jdesktop.layou t.GroupLayout.L EADING)
.add(layout.cre ateSequentialGr oup()
.addContainerGa p()
.add(layout.cre ateParallelGrou p(org.jdesktop. layout.GroupLay out.LEADING)
.add(jScrollPan e1, org.jdesktop.la yout.GroupLayou t.DEFAULT_SIZE, 366, Short.MAX_VALUE )
.add(layout.cre ateSequentialGr oup()
.add(layout.cre ateParallelGrou p(org.jdesktop. layout.GroupLay out.LEADING, false)
.add(jButton13, 0, 0, Short.MAX_VALUE )
.add(jButton5, org.jdesktop.la yout.GroupLayou t.DEFAULT_SIZE, org.jdesktop.la yout.GroupLayou t.DEFAULT_SIZE, Short.MAX_VALUE )
.add(jButton9, org.jdesktop.la yout.GroupLayou t.DEFAULT_SIZE, org.jdesktop.la yout.GroupLayou t.DEFAULT_SIZE, Short.MAX_VALUE )
.add(jButton1, org.jdesktop.la yout.GroupLayou t.PREFERRED_SIZ E, 87, org.jdesktop.la yout.GroupLayou t.PREFERRED_SIZ E))
.addPreferredGa p(org.jdesktop. layout.LayoutSt yle.RELATED)
.add(layout.cre ateParallelGrou p(org.jdesktop. layout.GroupLay out.LEADING)
.add(jButton10, 0, 0, Short.MAX_VALUE )
.add(jButton14, org.jdesktop.la yout.GroupLayou t.DEFAULT_SIZE, 86, Short.MAX_VALUE )
.add(jButton6, org.jdesktop.la yout.GroupLayou t.DEFAULT_SIZE, 86, Short.MAX_VALUE )
.add(jButton2, org.jdesktop.la yout.GroupLayou t.DEFAULT_SIZE, 86, Short.MAX_VALUE ))
.addPreferredGa p(org.jdesktop. layout.LayoutSt yle.RELATED)
.add(layout.cre ateParallelGrou p(org.jdesktop. layout.GroupLay out.LEADING)
.add(jButton7, org.jdesktop.la yout.GroupLayou t.DEFAULT_SIZE, 91, Short.MAX_VALUE )
.add(org.jdeskt op.layout.Group Layout.TRAILING , jButton3, org.jdesktop.la yout.GroupLayou t.PREFERRED_SIZ E, 90, org.jdesktop.la yout.GroupLayou t.PREFERRED_SIZ E)
.add(jButton15, org.jdesktop.la yout.GroupLayou t.DEFAULT_SIZE, 91, Short.MAX_VALUE )
.add(layout.cre ateSequentialGr oup()
.addPreferredGa p(org.jdesktop. layout.LayoutSt yle.RELATED)
.add(jButton11, org.jdesktop.la yout.GroupLayou t.PREFERRED_SIZ E, 91, org.jdesktop.la yout.GroupLayou t.PREFERRED_SIZ E)))
.addPreferredGa p(org.jdesktop. layout.LayoutSt yle.RELATED)
.add(layout.cre ateParallelGrou p(org.jdesktop. layout.GroupLay out.TRAILING)
.add(org.jdeskt op.layout.Group Layout.LEADING, layout.createSe quentialGroup()
.add(layout.cre ateParallelGrou p(org.jdesktop. layout.GroupLay out.LEADING)
.add(jButton16, 0, 0, Short.MAX_VALUE )
.add(jButton12, 0, 0, Short.MAX_VALUE )
.add(layout.cre ateSequentialGr oup()
.add(jButton8, org.jdesktop.la yout.GroupLayou t.PREFERRED_SIZ E, 84, org.jdesktop.la yout.GroupLayou t.PREFERRED_SIZ E)
.addPreferredGa p(org.jdesktop. layout.LayoutSt yle.RELATED)))
.addPreferredGa p(org.jdesktop. layout.LayoutSt yle.RELATED))
.add(jButton4, org.jdesktop.la yout.GroupLayou t.PREFERRED_SIZ E, 84, org.jdesktop.la yout.GroupLayou t.PREFERRED_SIZ E))))
.addContainerGa p())
);
layout.setVerti calGroup(
layout.createPa rallelGroup(org .jdesktop.layou t.GroupLayout.L EADING)
.add(layout.cre ateSequentialGr oup()
.addContainerGa p()
.add(jScrollPan e1, org.jdesktop.la yout.GroupLayou t.PREFERRED_SIZ E, org.jdesktop.la yout.GroupLayou t.DEFAULT_SIZE, org.jdesktop.la yout.GroupLayou t.PREFERRED_SIZ E)
.addPreferredGa p(org.jdesktop. layout.LayoutSt yle.RELATED)
.add(layout.cre ateParallelGrou p(org.jdesktop. layout.GroupLay out.BASELINE)
.add(jButton4, org.jdesktop.la yout.GroupLayou t.PREFERRED_SIZ E, 66, org.jdesktop.la yout.GroupLayou t.PREFERRED_SIZ E)
.add(jButton3, org.jdesktop.la yout.GroupLayou t.PREFERRED_SIZ E, 66, org.jdesktop.la yout.GroupLayou t.PREFERRED_SIZ E)
.add(jButton2, org.jdesktop.la yout.GroupLayou t.PREFERRED_SIZ E, 64, org.jdesktop.la yout.GroupLayou t.PREFERRED_SIZ E)
.add(jButton1, org.jdesktop.la yout.GroupLayou t.PREFERRED_SIZ E, 65, org.jdesktop.la yout.GroupLayou t.PREFERRED_SIZ E))
.add(layout.cre ateParallelGrou p(org.jdesktop. layout.GroupLay out.LEADING)
.add(layout.cre ateSequentialGr oup()
.addPreferredGa p(org.jdesktop. layout.LayoutSt yle.RELATED)
.add(layout.cre ateParallelGrou p(org.jdesktop. layout.GroupLay out.BASELINE)
.add(jButton5, org.jdesktop.la yout.GroupLayou t.PREFERRED_SIZ E, 65, org.jdesktop.la yout.GroupLayou t.PREFERRED_SIZ E)
.add(jButton7, org.jdesktop.la yout.GroupLayou t.PREFERRED_SIZ E, 64, org.jdesktop.la yout.GroupLayou t.PREFERRED_SIZ E)
.add(jButton6, org.jdesktop.la yout.GroupLayou t.PREFERRED_SIZ E, 64, org.jdesktop.la yout.GroupLayou t.PREFERRED_SIZ E)))
.add(layout.cre ateSequentialGr oup()
.add(6, 6, 6)
.add(jButton8,
Dec 14 '06 #1
5 2133
erekose666
23 New Member
Here's the rest of the code:

org.jdesktop.la yout.GroupLayou t.PREFERRED_SIZ E, 65, org.jdesktop.la yout.GroupLayou t.PREFERRED_SIZ E)))
.addPreferredGa p(org.jdesktop. layout.LayoutSt yle.RELATED)
.add(layout.cre ateParallelGrou p(org.jdesktop. layout.GroupLay out.LEADING)
.add(jButton11, org.jdesktop.la yout.GroupLayou t.DEFAULT_SIZE, 67, Short.MAX_VALUE )
.add(jButton12, org.jdesktop.la yout.GroupLayou t.DEFAULT_SIZE, 67, Short.MAX_VALUE )
.add(layout.cre ateParallelGrou p(org.jdesktop. layout.GroupLay out.LEADING, false)
.add(org.jdeskt op.layout.Group Layout.TRAILING , jButton9, org.jdesktop.la yout.GroupLayou t.DEFAULT_SIZE, 67, Short.MAX_VALUE )
.add(org.jdeskt op.layout.Group Layout.TRAILING , jButton10, org.jdesktop.la yout.GroupLayou t.DEFAULT_SIZE, org.jdesktop.la yout.GroupLayou t.DEFAULT_SIZE, Short.MAX_VALUE )))
.addPreferredGa p(org.jdesktop. layout.LayoutSt yle.RELATED)
.add(layout.cre ateParallelGrou p(org.jdesktop. layout.GroupLay out.LEADING)
.add(layout.cre ateParallelGrou p(org.jdesktop. layout.GroupLay out.BASELINE)
.add(jButton14, org.jdesktop.la yout.GroupLayou t.PREFERRED_SIZ E, 66, org.jdesktop.la yout.GroupLayou t.PREFERRED_SIZ E)
.add(jButton15, org.jdesktop.la yout.GroupLayou t.PREFERRED_SIZ E, 66, org.jdesktop.la yout.GroupLayou t.PREFERRED_SIZ E))
.add(jButton16, org.jdesktop.la yout.GroupLayou t.DEFAULT_SIZE, 67, Short.MAX_VALUE )
.add(jButton13, org.jdesktop.la yout.GroupLayou t.PREFERRED_SIZ E, 66, org.jdesktop.la yout.GroupLayou t.PREFERRED_SIZ E))
.addContainerGa p())
);
pack();
}// </editor-fold>

private void jButton13KeyPre ssed(java.awt.e vent.KeyEvent evt) {
// TODO add your handling code here:
}

private void jButton13Action Performed(java. awt.event.Actio nEvent evt) {


// TODO add your handling code here:
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQ ueue.invokeLate r(new Runnable() {
public void run() {
new Calculator().se tVisible(true);
}
});
}

// Variables declaration - do not modify
private javax.swing.JBu tton jButton1;
private javax.swing.JBu tton jButton10;
private javax.swing.JBu tton jButton11;
private javax.swing.JBu tton jButton12;
private javax.swing.JBu tton jButton13;
private javax.swing.JBu tton jButton14;
private javax.swing.JBu tton jButton15;
private javax.swing.JBu tton jButton16;
private javax.swing.JBu tton jButton2;
private javax.swing.JBu tton jButton3;
private javax.swing.JBu tton jButton4;
private javax.swing.JBu tton jButton5;
private javax.swing.JBu tton jButton6;
private javax.swing.JBu tton jButton7;
private javax.swing.JBu tton jButton8;
private javax.swing.JBu tton jButton9;
private javax.swing.JSc rollPane jScrollPane1;
private javax.swing.JTe xtPane jTextPane1;
// End of variables declaration

}
Dec 14 '06 #2
erekose666
23 New Member
Isn't there some way to do like a .append to do this?
My big problem is like entering a number that is more than one digit
Say i want to type in 4562 and have it appear in the screen above
This program doesnt need to actually DO any calculations
Just show the numbers that are pressed on the keypad
Dec 14 '06 #3
erekose666
23 New Member
OK let's make this easier for everyone :)
I know that doing an OnActionPerform ed
and then doing jTextPane1.setT ext("1") will send a 1 to the TextPane

My question is...how do i send 4563? After pressing the 4 button, the TextPane shows a 4, but then when I press the 5 button the TextPane shows a 5. I want to be able to send the 4, then put the 5 after it then the 6 etc etc.


Any help?
Dec 15 '06 #4
r035198x
13,262 MVP
OK let's make this easier for everyone :)
I know that doing an OnActionPerform ed
and then doing jTextPane1.setT ext("1") will send a 1 to the TextPane

My question is...how do i send 4563? After pressing the 4 button, the TextPane shows a 4, but then when I press the 5 button the TextPane shows a 5. I want to be able to send the 4, then put the 5 after it then the 6 etc etc.


Any help?
Each button should have an actionCommand set for it(Which is simply a String). eg button 1 would have "1" as its command etc.

In the actionPerformed method you then do

Expand|Select|Wrap|Line Numbers
  1.  String command = event.getActionCommand(); 
  2. if(command.equals("1")) {
  3.     String current = pane.getText();
  4.     pane.setText(current + "1");//do the append
  5. }
  6.  
Dec 15 '06 #5
trinisoftinc
4 New Member
public void actionPerformed (ActionEvent ae) {
//firstTime is boolean. It helps you know if the number is the first
//textPane is a JTextBox(or JTextArea anyhow)
if(firstTime) {
//just display the typed key
textPane.setTex t(ae.getActionC ommand());
firstTime = false;
}
else
{
//get the content of the textPane
String ss = textPane.getTex t();
//concat it to the typed key
ss = ss + ae.getActionCom mand();
//display the concated(if there's anything like that)
textPane.setTex t(ss);
}
}
please dont reply if this works just lookup to the sky and shout a very big thank you
Dec 21 '06 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

45
16827
by: Market Mutant | last post by:
I just wonder job selections, job openings and salary level of PHP programer or Perl programmer comparing to Java programmers. Is Java programmer's salary has a minimal of 60K in US? Are there many PHP jobs?
0
1173
by: Brian | last post by:
I've got one master machine containing several databases and two other machines which I want to be slaves. However, I want each slave to only replicate some of the databases from the master, not all of them. eg. host "master" has databases "db1", "db2" and "db3" host "slave1" wants to replicate "db1" and "db2" only host "slave2" wants to...
0
1143
by: melledge | last post by:
The Reliable Source for Everything XML - XML 2005 Update XML 2005 - November 14-18 - Atlanta Hilton Hotel - Atlanta, GA www.xmlconference.org Register today and participate in IDEAlliance's XML 2005 Conference, the most respected educational gathering of technologists, novices, experienced implementers and users, consultants, and...
3
4888
by: fiNAL.Y | last post by:
Many C++ masters recommend us not to use Macros in C++ but to use inline functions and const . But I think that Macros can do something inline functions and const cannot do. It can "extend" the language in some degree. For example, when we use MFC, there're many helper Macros without which our work wouldn't be so easy and when I'm using...
10
2926
by: Ray | last post by:
I am reading Andrei Alexandrescu's book. The ideas presented there sound really good, but I wonder--is there really a lot of people using it? Or it's simply too esoteric for mortals? Cheers Ray
0
1284
by: luffmusse | last post by:
We are two students from the Royal Institute of Technology in Stockholm, Sweden (http://www.kth.se/eng/). We are currently doing our masters thesis in Applied Information Technology where we specialize in security. As a part of this thesis we will do a survey where we compare general information about software organizations and software...
2
1849
by: Andy Dingley | last post by:
http://bingweb.binghamton.edu/~tony/cake.jpg From: http://community.livejournal.com/good_eats/507059.html
3
1490
roula
by: roula | last post by:
Hi, I am using cake php for a website, and it was all working fine my local pc, but when I uploaded it on the host it gave me this error without showing anything: Flash('The Content deleted: id '.$id.''); $this->redirect('/contents/index'); } } } ?> on line Fatal error: Cannot instantiate non-existent class: contentscontroller in ...
28
1893
by: RMZ | last post by:
This may come across as a trolling message, it's not ment to be. It's intended to share a recent experience I had with Mac OS in an entertaining way. I'm doing this because I love technology in general and most programmers I know are passionate about technology, unfortunately many of them stay away from Mac. Some as if it's the forbidden...
0
7694
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7921
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8118
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7666
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.