2016-12-19 49 views
0

的数据被存储在一个名为Jobs.json此文件是文件:JFrame“窗口”及其内容不显示,为什么?

[ 
{ 
    "JobTitle":" Computer Programmer", 
    "field":"Software Development", 
    "Company":"Ideal Life", 
    "Education":"Any undergraduate degree", 
    "Salary":"$68,500 - $75,000 a year", 
    "Hours":"37.5 hours per week", 

    "Experience":"Solid coding chops with HTML, CSS, Javascript; this includes JQuery and Bootstrap", 

    "Responsibilities":"Assist in producing data exports/reports via SQL query routines", 

    "University":"Bachelor of Engineering:\nEnglish/Anglais (ENG4U/EAE4U preferred)\nAdvanced Functions (MHF4U)\nPhysics (SPH4U)\nChemistry (SCH4U)\nCalculus and Vectors (MCV4U)\nGrades should be 80-87% for consideration.", 
    "College":"N/A" 
}, 
{ 
    "JobTitle":"IT Specialist", 
    "field":"IT", 
    "Company":"Meriti Wealth Advisors Inc", 
    "Education":"a diploma/degree in Computer Science", 
    "Salary":"$68,500 - $75,000 a year", 
    "Hours":"Not given", 
    "Experience":"sample text", 
    "Responsibilities":"more sample text", 
    "University":"Low 90%s to consider", 
    "College":"N/A" 
}, 
{ 

    "JobTitle":"Computer Programmer", 
    "field":"Computer Software", 
    "Company":"IBM", 
    "Education":"Bachelor’s degree in Computer Science, Software Engineering or equivalent", 
    "Salary":"Not given", 
    "Hours":"Not given", 
    "Experience":"responsive web applications", 
    "Responsibilities":"Work alongside our multidisciplinary team of developers and designers", 
    "University":"Low 90%s to consider", 
    "College":"N/A" 
}, 
{ 
    "JobTitle":"Computer programmer", 
    "field":"Computer Software/Transportation Management", 
    "Company":"Degama", 
    "Education":"College, or other non-university certificate or diploma from a program of 1 year to 2 years", 
    "Salary":"$73,000.00 per year", 
    "Hours":"40 hours per week", 
    "Experience":"Experience an asset", 
    "Responsibilities":"Write, modify, integrate and test software code;", 
    "University":"N/A", 
    "College":"(Seneca Computer Programming Diploma)\nOntario Secondary School Diploma (OSSD) or equivalent with:\nGrade 12 English: ENG4(C) or ENG4(U)\nGrade 12 Mathematics: (C) or (U) or Grade 11 Mathematics: (U) or (M)" 
}, 
{ 
    "JobTitle":"Software Test Engineer", 
    "field":"Auto industry", 
    "Company":"General Motors", 
    "Education":"Bachelor's degree in Computer Science, Software Engineering, or equivalent field", 
    "Salary":"Not given", 
    "Hours":"Not given", 
    "Experience":"Advanced degrees preferred", 
    "Responsibilities":"Define test strategy and test plan based on software development plan", 
    "University":"Low 90%s to consider", 
    "College":"N/A" 
} 
] 

这是我写的java程序,我想在程序的JSON文件保存一切,把职称成一个组合框。

import java.awt.Color; 
import java.awt.Font; 
import java.io.File; 
import java.io.FileNotFoundException; 
import java.util.Scanner; 
import java.awt.Graphics; 
import java.awt.GridBagConstraints; 
import java.awt.GridBagLayout; 
import java.awt.Image; 
import java.awt.Insets; 
import java.awt.Panel; 
import java.awt.event.ActionEvent; 
import java.awt.event.ActionListener; 
import java.awt.image.BufferedImage; 

import javax.swing.ImageIcon; 
import javax.swing.JButton; 
import javax.swing.JFrame; 
import javax.swing.JLabel; 
import javax.swing.JPanel; 
import javax.swing.JComboBox; 


import org.json.JSONArray; 
import org.json.JSONObject; 


public class Main 
{ 
    static Scanner input; 
    static String file; 
    static String[] jobs; 
    static String[] field; 
    static String[] company; 
    static String[] education; 
    static String[] salary; 
    static String[] hours; 
    static String[] experience; 
    static String[] responsibilities; 
    static String[] university; 
    static String[] college; 
    static JComboBox<String> combo = new JComboBox <String>() 


public static void main(String[] args) 
{ 
    try 
    { 
     input = new Scanner(new File("Jobs.json")); 
    } 
    catch(FileNotFoundException e) 
    { 
     System.out.println("error"); 
    } 
    while(input.hasNextLine()); 
    { 
     file+=input.nextLine(); 
    } 
    final JSONArray jason=new JSONArray(file); 
    for(int a=0;a<jason.length();a++) 
    { 
     JSONObject object=jason.getJSONObject(a); 
     jobs[a]=object.getString("JobTitle"); 
     field[a]=object.getString("field"); 
     company[a]=object.getString("Company"); 
     education[a]=object.getString("Education"); 
     salary[a]=object.getString("Salary"); 
     hours[a]=object.getString("Hours"); 
     experience[a]=object.getString("Experience"); 
     responsibilities[a]=object.getString("Responsibilities"); 
     university[a]=object.getString("University"); 
     college[a]=object.getString("College"); 
     combo.addItem(jobs[a]); 
    } 
    JFrame jframe = new JFrame("Window"); 
    jframe.setSize(640, 480); 
    jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
    jframe.setVisible(true); 


    JPanel jpanel = new JPanel(); 
    jpanel.setBackground(Color.CYAN); 

    GridBagLayout layout = new GridBagLayout(); 
    GridBagConstraints constraints = new GridBagConstraints(); 

    final JLabel label = new JLabel(" "); 
    label.setFont(new Font("Ariel", Font.PLAIN, 14)); 

    JButton button = new JButton("Press for Info"); 
    button.addActionListener(new ActionListener() 
    { 
     @Override 
     public void actionPerformed(ActionEvent e) 
     { 

      label.setText(combo.getSelectedItem().toString()); 
     } 

    }); 

      //Add to the jpanel 
      jpanel.setLayout(layout); 
      constraints.anchor = GridBagConstraints.NORTHWEST; 
      constraints.gridx = 0; 
      constraints.gridy = 0; 
      constraints.weightx = 1; 
      constraints.fill = GridBagConstraints.HORIZONTAL; 
      //insets(top, left, bottom, right); 
      constraints.insets = new Insets(0,0,0,200); 
      jpanel.add(combo,constraints); 

      //Add Button 
      constraints.gridx = 0; 
      constraints.gridy = 1; 
      constraints.weightx = 0.1; 
      constraints.fill = GridBagConstraints.NONE; 
      //insets(top, left, bottom, right); 
      constraints.insets = new Insets(0,0,0,0); 
      jpanel.add(button,constraints); 

      //Add label 
      constraints.gridx = 0; 
      constraints.gridy = 2; 
      constraints.insets = new Insets(10,0,0,0); 
      jpanel.add(label,constraints); 

      //Add the panel container to our window 
      jframe.add(jpanel); 
      jframe.setVisible(true); 
} 

}

+0

会发生什么情况?该程序只是终止没有任何窗口?或者它挂起?你可以在任何IDE或命令行中看到它。 – Mordechai

+0

当我运行程序时,会在任务栏上打开一个java文件,但是当我单击任务栏中的“显示所有窗口”时,不会显示窗口。 –

回答

1

main method

你现在的代码将运行到无限循环替换

while(input.hasNextLine()); 

while(input.hasNextLine())