To write an application that simulates a calculator, using the Panel and grid layout, add a text box, 10 number buttons (0~9), 4 subtraction buttons, an equal sign button, a purge button, a square root button, a backspace button that asks the calculation formula and results to be displayed in a text box. The implementation effect is shown in the following illustration.
Java Simple
Because it is a novice (very pure kind), so a bit messy, the code is very redundant (will be condensed later), naming rules please ignore. Of course, this calculator is only able to run up to the extent that there will be some inexplicable error, such as my index operation index only support integers and so on. After all, it is the first time to write a small thing alone, still very happy.1. Main section (L
Make a calculator like ageAccording to the topic, I made a calendar class and the date of the month and the day of the age, of course, the correct way more than one, the following is my source code and results:Package com. Date;Import Java.awt.FlowLayout;Import java.awt.event.ActionEvent;Import Java.awt.event.ActionListener;Import Java.sql.Date;Import Java.util.Calendar;Import java.util.EmptyStackException;
The Code repetition rate is too high. It should be optimized and there is no time.
The setactioncommand () method can greatly reduce the amount of code.Code:
Import java. AWT .*;
Import java. AWT. event .*;
Import javax. Swing .*;
Public class test1 {
Public static void main (string [] ARGs ){
Calculator c = n
implemented by invoking the methods in each package, and we have a good understanding of the relationship between package and class invocation.After the experiment is completed, she organizes the code, organizes the general flow of the experiment report, and organizes the job submission format. And I am responsible for the final program inspection and calibration. Make sure there are no obvious unreasonable places. B,
The Set calculator assists java in processing the set operation of Structured Text
JAVA does not directly support set operations. Therefore, you must use nested loops to perform set operations such as intersection, union, and difference sets between text files. If there are many files, or if the file is large and cannot be directly computed in the memory, or you
In fact, this Android computer, all the backstage ideas and "C # calculator Code" is exactly the same. The Win form program is ported to Android, from C # to Java in fact, because the basic syntax is very similar, the only difficulty is the Android XML layout part, unlike C # forms can be directly dragged.Or a calculator
The code is as follows:Import Java.awt.*;import javax.swing.*;p ublic class Gridframe extends JFrame {//define string array, assign a value to the display text of the button string str[] = {"MC", "MR", "MS", "m+", "←", "C", "%", "π", "7", "8", "9", "/", "4", "5", "6", "*", "1", "2", "3", "-", "0", ".", "=", "+"};p UBL IC Gridframe () {//define panel and set to Grid layout, 4 rows 4 columns, component horizontal, vertical spacing is 7JPanel pan = new J
The next Saturday to take part in test practice on the machine exam, time too fast, cold days people also become lazy, and sometimes do not want to do, tonight just have time to take out the Java test Questions to review, read more sleepy simply knock code it, to tell the truth I am not very familiar with Java, If it is not for the exam to test, I do not have tim
Today, I simply tried out Java programming and wrote a short calculator that contained only +,-,*,/. Today, make a brief summary of the calculator.First, the calculator is divided into input, calculation, output 3 links, the first to introduce the next input link.Input:We need to tap 2 numbers to calculate from the keyboard, and an operator for an operation. The
(Cstack.peek ()! = ' (') {//until you can match the opening parenthesis intA =Istack.pop (); intc =Cstack.pop (); if(c = = ' + ')) {Temp+=A; }Else if(c = = '-')) {Temp-=A; }} Temp+ = Istack.pop ();//plus the number after the opening parenthesisIstack.push (temp); Cstack.pop (); } } returnIstack.pop (); }}Train of thought 2 (suffix expression): The general method of calculation, the operation of parentheses into a non-parenthesized suffix expres
First, the purpose of the experiment1. Familiar with Java graphical user interface design principles and program structure2. Able to design a graphical user interface program to review the problem requirements3. Familiar with the combination of Java AWT and swing4. Mastering the usual set-up of event excuses5. Application design using AWT and swing componentsSecond, the experimental conditions1.PC Machine O
This is a web version that I use Java Script to run on a browser:
The above is a calculator that I drew using HTML based on the table control plus button and text box control.CodeNot yet written. It's too late today. Let's go to bed first and update this
perform the addition of numbers, with the following specific code: Packagecom.cqvie.action;ImportCom.opensymphony.xwork2.ActionSupport; Public classUseractionextendsActionsupport {Private intnum1, num2, sum; Public intgetNum1 () {returnNUM1; } Public voidSETNUM1 (intNUM1) { This. NUM1 =NUM1; } Public intgetNum2 () {returnnum2; } Public voidSETNUM2 (intnum2) { This. num2 =num2; } Public intgetsum () {returnsum; }
Java tip 94: How to Use servlet to open documents in non-HTML Format A Simple Method for sending non-HTML documents to a Web Client By Marla Bonar
SummaryJava Servlet programming can easily send HTML files to the client web browser. However, many sites also allow access to documents in non-HTML format, including Adobe PDF, Microsoft Word, and micorsoft excel. In fact, as long as thes
Java tip 105: Use jwhich to master the class pathDetermine which classes in the class path will be loaded
Prepared by Mike ClarkSummaryAlthough Java class paths seem to be a simple concept, they are often the source of confusion and trouble. This article will show you a simple tool that can clearly determine what Java
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.