⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addintgui.java

📁 enter two number given by user and add the two number . This program with the GUI.
💻 JAVA
字号:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;


public class addintgui
{
   public static void main(String[] args)
   {
      SwingFrame frame = new SwingFrame();
      frame.setTitle("DemoSwing");
      frame.pack();
      frame.show();
   }
}


class SwingFrame extends JFrame implements ActionListener 
{    

    JLabel     num1Label;
	JLabel     ansLabel1;
	JTextField num1;
	JTextField answer1;
	JButton    addButton;
	
public SwingFrame()
   { 
   	    Container container = getContentPane();
		container.setLayout( new FlowLayout() );
		num1Label = new JLabel("Please enter a number <1000:");
	    ansLabel1 = new JLabel("sum all integer:");
		num1 = new JTextField( 8 );
        answer1 = new JTextField( 8 );
        addButton = new JButton("         Calculate          ");
		container.add( num1Label );
		container.add( num1 );
		container.add( addButton );
		container.add( ansLabel1 );
		container.add( answer1 );
	//	addButton.addActionListener(this);
		
		
   }
   
   public void actionPerformed( ActionEvent e ) {
		String string1 = num1.getText();
	//	String n2Str = num2.getText();
		int number2= Integer.parseInt(string1);
		int num1 = number2/100;
		int num2 = number2%100;
		
		int num3 = num2 /10;
		int num4 = num2 % 10;
		
		int sum = num1+num3+num4;
		
		answer1.setText(sum+"" );
	//	answer2.setText( num3+"" );
	//	answer3.setText( num4+"" );
	}
	
	private class WindowCloser extends WindowAdapter
   {
      public void windowClosing(WindowEvent event)
      {
         System.exit(0);
      }
   }
   
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -