• Post Reply Bookmark Topic Watch Topic
  • New Topic

JOptionPane.showInputDialog  RSS feed

 
Beverley Tudor
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am very new to Java and this is my first post.

I am trying to complete an assignment and wanted to use a dialog box to prompt for user input. My code will run without errors but I do not get the input box. I have used input boxes once before and cannot see what I have done different to stop it working. My code:

package mylittleassignment;

/**
* Title: Unit 5 Assignment Question 4
* Description: model of CASS assignment
* Copyright: Copyright (c) 2005
* Company: BeeTee
* @author Beverley Tudor
* @version 1.0
*/
import javax.swing.*;
public class Unit {
static String casscode;
static String submissiondate;
static String title;
int markstotal; // setting up attribute fields

public Unit (String c, String s, String t, int m) {
casscode = c;
submissiondate = s;
title = t;
markstotal = m;
} // this is the constructor

public static void main (String [] args){
System.out.println("Welcome to process for entering student assignment marks for unit5");
}

Unit mylittleassignment = new Unit("DLDC05-Unit5", "October 29", "mylittleassignment", 0 );
// the markstotal is set to zero as when the marks are earned they will be added through
// my setter method

public void setmarkstotal(){
String inputvalue = JOptionPane.showInputDialog("Enter the students mark out of 100.");
markstotal=Integer.parseInt(inputvalue);
}

public String getcasscode (){
return casscode; }
public String getsubmissiondate () {
return submissiondate; }
public String gettitle (){
return title;}
public int getmarkstotal () {
return markstotal; }





}


I would really appreciate it if someone could tell me where I am going wrong.

Bev
 
Seb Mathe
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your code is just the copy you've posted, it does simply output "Welcome to process for entering student assignment marks for unit5"

Look at your main method, you just call System.out.println().

I think the line where you declare a new Unit should be in your main method.

The call to JOptionPane.showInputDialog is done within setmarkstotal, which is never called...

There's a lot of others things which are bad in your code (even if it compiles ) : static members which should not be static, wrong methods name (regarding conventions of accessors/mutators methods ie getters/setters).
 
Stephen Boston
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure where you are heading with this Bev, but I cleaned up your code a bit to demostrate what Seb was talking about. Your JOptionPane will show now.

Does that help?

Steve

 
Beverley Tudor
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve

Thank you, I just couldn't see why I wasn't getting the input box to display. I am very new to Java and so far the course is telling us to ignore static which is probably why I have misused them.

I am determined to get to grips with this.

thanks again

Bev
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Beverley Tudor:
Steve

Thank you, I just couldn't see why I wasn't getting the input box to display. I am very new to Java and so far the course is telling us to ignore static which is probably why I have misused them.

I am determined to get to grips with this.

thanks again

Bev


They're telling you to ignoer static? God...the crap people are teaching.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!