joptionpane

Ask user if wants to quit via JOptionPane

早过忘川 提交于 2019-12-25 11:47:22
问题 I'm using this code to confirm the user whether wants to quit or not when he CLICKS THE RED CROSS CLOSE BUTTON OF JFrame (right upper corner) Object[] options = {"Quit, My Computing Fellow", "No, I want to Work more"}; int Answer = JOptionPane.showOptionDialog(null, "What would you like to do? ","Quit:Continue", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options,options[1]); if(Answer == JOptionPane.YES_OPTION){ System.exit(0); } else if (Answer == JOptionPane.CANCEL

Need to make a receipt which aligns item's prices (using javax.swing.* could import others if needed)

蹲街弑〆低调 提交于 2019-12-25 08:58:42
问题 I need to make a program that displays a receipt for any company. So, the user should enter the company name, date, time, name and price of four items purchased and the program should add the prices to arrive at the total and should display like the pic below. Here's what I have till now:- import javax.swing.*; public class Receipt { public static void main(String[] args) { String companyName; String itemName1; String itemName2; String itemName3; String itemName4; double item1; double item2;

Re-prompting the user for data input with an if statement

陌路散爱 提交于 2019-12-25 08:42:04
问题 I'm trying to prompt for a first/last name in this code, but I cannot figure out how to re-prompt a user for the name if they forget to fill out the field. Right now if my code does not get any input and the user clicks onwards, I have it so a message box will pop up and then the program will close. I want to be able to just re-prompt for the exact same step without it getting all out of order. This is what I have so far: public void getValues(){ firstName = JOptionPane.showInputDialog(null,

Color of JOptionPane border

佐手、 提交于 2019-12-25 05:27:16
问题 How might I go about changing the color of a JOptionPane's border ? Here is a screenshot of the border I am talking about: That blue border is what I am trying to get rid of. I tried to set UIManager.put("OptionPane.border", new BorderFactory...) for LookAndFeel but that changed the inside border, not the outermost one. I need to get rid of that blue border. Any ideas? -Mark 回答1: Read the JOptionPane API . It shows you how to create a JOption pane manually so that you have access to the

How to use JOptionPane to input data into an array

只谈情不闲聊 提交于 2019-12-25 05:06:38
问题 how do i create an array where I want there to be 8 values in an array but the user inputs them? this is what i have so far import javax.swing.JOptionPane; public class Southside Report { public static void main(String[] args) { int FINAL MIN_STAFF = 7; int total_staff = 0; double[] num_students = 8; 回答1: you should declare your array as: double[] num_students = new double[8]; And int FINAL MIN_STAFF = 7; should be FINAL int MIN_STAFF = 7; Then you may assign the value using JOptionPane by

Comparing Strings in Java .equals()

感情迁移 提交于 2019-12-25 03:19:22
问题 I'm trying to filter the user's input to make sure its a max of 4 digits and it's not an empty string. Whether I leave it blank or I enter a number, !strInput.equals(null) still comes up true. Am I comparing the string incorrectly? I also tried: !strInput.equals("") , strInput != null , and strInput != "" though I think it should be .equals(...) since I'm trying to compare values. private void updateFast() { String strInput = JOptionPane.showInputDialog(null, "How many?"); if (!strInput

(Java) How to Keep Track of Numbers Entered by User for Determining Min and Max

巧了我就是萌 提交于 2019-12-25 01:43:33
问题 I have a homework assignment that is asking me to use an input dialog to ask the end user to enter a number, parse that String to an int, and then use a confirm dialog to ask if the user wants to enter another number. If they click yes, the program loops, and once they hit no, it takes all of the entered numbers and determines the min and max. How do I keep track of all the entered numbers without declaring multiple variables to hold them (since the user can technically enter an infinite

How can I get make my program wait until JavaFX window has been closed before continuing?

孤街浪徒 提交于 2019-12-24 08:47:50
问题 I have a program that is displaying a barchart of results. I want to wait until the user closes the bar chart to continue to the next line of code which is asking if they want to enter new information for the chart. Scene scene = BarGraph.getBarChart(); primaryStage.setScene(scene); primaryStage.setTitle("Bar Chart"); primaryStage.show(); repeat = JOptionPane.showConfirmDialog(null, "Would you like to enter another number?"); What is happening is the scene for the bar chart will open, but

GrahicsDevice and JOptionPane Issue

Deadly 提交于 2019-12-24 06:07:42
问题 When I click the button, the application which is set to full screen will go to taskbar/minimized, so I need to click it first in the taskbar before seeing the JOptionPane that I triggered. What do you think is the problem with this? I'd like it to run smoothly without being minimized or going to taskbar. public static void main(String[] args) { final JFrame frame = new JFrame(); frame.setTitle("Sample"); GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment()

how to set & manage the layout of JOptionPane

戏子无情 提交于 2019-12-24 05:34:12
问题 I have a simple JOptionPane with some components and I want to arrange them. For example I want to put the label next to the text/password field, sets their width etc.. This is like how I did it, of course the result wasn't what I wanted: public class CreateApplicationUserScreen { CreateApplicationUserScreen(){ JLabel l_name=new JLabel("Username"); JLabel l_pass=new JLabel("Password"); JTextField tf_name=new JTextField(10); JPasswordField pf_pass=new JPasswordField(10); JButton b_privs = new