Skip to Main Content

Problem with JTextField

User_AYF65Jun 17 2015 — edited Jun 30 2015


i am trying to use JTextField. I have windows 7.I have jdk 8u45. I am trying to use multiple text boxes. I have written the following code:

import javax.swing.*;

import java.awt.*;

class Avg5Nums{

int num1, num2, num3, num4, num5;

double Avg;

Avg5Nums(int val1, int val2, int val3, int val4, int val5) {

num1 = val1;

num2 = val2;

num3 = val3;

num4 = val4;

num5 = val5;


double getAvg(){

int sum = num1 + num2 + num3 + num4 + num5;

Avg = sum/5;

return Avg;



class useAvg5Nums extends JFrame{

public static void man(String args[]) {

JTextField field1 = new JTextField();

JTextField field2 = new JTextField();

JTextField field3 = new JTextField();

JTextField field4 = new JTextField();

JTextField field5 = new JTextField();

Object[] message = {

    "Input value 1:", field1,

    "Input value 2:", field2,

    "Input value 3:", field3,

    "Input value 4:", field4,

    "Input value 5:", field5,


int val1, val2, val3, val4, val5;

val1=0; val2=0; val3=0; val4=0; val5=0;

int option = JOptionPane.showConfirmDialog(null, null, "Enter all your values", JOptionPane.OK_CANCEL_OPTION);

if (option == JOptionPane.OK_OPTION)


    String value1 = field1.getText();

    String value2 = field2.getText();

    String value3 = field3.getText();

    String value4 = field4.getText();

    String value5 = field5.getText();

val1 = Integer.parseInt(value1);

val2 = Integer.parseInt(value2);

val3 = Integer.parseInt(value3);

val4 = Integer.parseInt(value4);

val5 = Integer.parseInt(value5);


Avg5Nums obj = new Avg5Nums(val1, val2, val3, val4, val5);

double Avg = obj.getAvg();

JOptionPane.showMessageDialog(null, "The Average is " + Avg, "results", JOptionPane.PLAIN_MESSAGE);




I am getting following error:

G:\Zulfi\java prog\2015\joptionPane>java useAvg5Nums

Error: Main method not found in class useAvg5Nums, please define the main method


   public static void main(String[] args)

or a JavaFX application class must extend javafx.application.Application

G:\Zulfi\java prog\2015\joptionPane>

can some body please guide me.


This post has been answered by TPD-Opitz on Jun 17 2015
Jump to Answer
Post Details
Added on Jun 17 2015