基本上,有2幀: 「StartUpFrame」 和 「ActivityScreen」 的StartUpFrame製成使用純粹Netbeans的GUI,而ActivityScreen通過編碼而沒有任何的Netbeans GUI製成。java的編譯錯誤:-Xlint引起問題
在StartUpFrame上,當我按下「活動列表」按鈕時,它應該將框架切換到ActivityScreen,這應該是一個非常簡單的操作。
然而,當我在自己的編譯ActivityScreen,它給了我一些類似的警告:
「注:F:\的Java \實驗室8 \ Lab8.java使用未經檢查或不安全的操作注意:重新編譯-Xlint:未檢查細節「, 但該文件仍然編譯。
當我嘗試編譯StartUpFrame,錯誤似乎導致問題與按鈕的動作,無法調用類的適當
我只是想不通的問題是什麼。
的StartUpFrame.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class StartUpFrame extends JFrame
{
//Creates new form StartUpFrame
public StartUpFrame()
{
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
title = new javax.swing.JLabel();
btnActivities = new javax.swing.JButton();
ButtonExit = new javax.swing.JButton();
btnStudents = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
title.setFont(new java.awt.Font("Arial", 0, 48)); // NOI18N
title.setText("ASA Magement Program");
btnActivities.setFont(new java.awt.Font("Arial", 0, 24)); // NOI18N
btnActivities.setText("List of Activities");
btnActivities.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnActivitiesActionPerformed(evt);
}
});
ButtonExit.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
ButtonExit.setText("Exit");
ButtonExit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ButtonExitActionPerformed(evt);
}
});
btnStudents.setFont(new java.awt.Font("Arial", 0, 24)); // NOI18N
btnStudents.setText("List of All Students");
btnStudents.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnStudentsActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap(233, Short.MAX_VALUE)
.addComponent(btnActivities)
.addGap(232, 232, 232))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(62, 62, 62)
.addComponent(title))
.addGroup(layout.createSequentialGroup()
.addGap(213, 213, 213)
.addComponent(btnStudents)))
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGap(258, 258, 258)
.addComponent(ButtonExit, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(title)
.addGap(103, 103, 103)
.addComponent(btnActivities)
.addGap(61, 61, 61)
.addComponent(btnStudents)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 110, Short.MAX_VALUE)
.addComponent(ButtonExit, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
pack();
setLocationRelativeTo(null);
}// </editor-fold>//GEN-END:initComponents
private void ButtonExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButtonExitActionPerformed
System.exit(0);
}//GEN-LAST:event_ButtonExitActionPerformed
private void btnActivitiesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnActivitiesActionPerformed
ActivityScreen AS = new ActivityScreen();
AS.setVisible(true);
setVisible(false);
}//GEN-LAST:event_btnActivitiesActionPerformed
private void btnStudentsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnStudentsActionPerformed
StudentScreen SS = new StudentScreen();
SS.setVisible(true);
setVisible(false);
}//GEN-LAST:event_btnStudentsActionPerformed
//the command line arguments
public static void main(String args[])
{
// Create and display the form
java.awt.EventQueue.invokeLater(new Runnable()
{
public void run()
{
new StartUpFrame().setVisible(true);
}
});
}
//note to self: NEED TO REMOVE "JAVAX.SWING."
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton ButtonExit;
private javax.swing.JButton btnActivities;
private javax.swing.JButton btnStudents;
private javax.swing.JLabel title;
// End of variables declaration//GEN-END:variables
}
ActivityScreen.java
import java.io.*;
import java.util.*;
import java.util.List;
import javax.swing.JTable;
import javax.swing.*;
import java.awt.*;
import java.awt.Component;
import java.awt.Container;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
class MyFrame extends javax.swing.JFrame
{
//Object[][] cell_value = { {"Sunday","Activity1","Activity2","Activity3"}, {"Monday","Activity4","Activity5","Activity6"}, {"Tuesday","Activity7","Activity8",""}};
Object[][] cell_value = new Object[0][5];
//String ColName[] = { "Title1", "Title2", "Title3", "Title4"};
String ColName[] = new String [5];
MyFrame()
{
try{
String s = "";
int n = 0;
int m = 0;
int rowcount = 0;
BufferedReader in = new BufferedReader(new FileReader("Days.dat"));
List list = Collections.synchronizedList(new LinkedList());
while ((s = in.readLine()) != null) {
if(!s.equals(""))
{
//System.out.println(s);
list.add(s);
if(s.equals("Sunday")) { ColName[0]=s; }
else if(s.equals("Monday")) { ColName[1]=s; }
else if(s.equals("Tuesday")) { ColName[2]=s; }
else if(s.equals("Wednesday")) { ColName[3]=s; }
else if(s.equals("Thursday")) { ColName[4]=s; }
else {rowcount ++;}
}
}
in.close();
cell_value = new Object[rowcount][5];
for(int i = 0
; i< list.size();i++)
{
if(list.get(i).equals("Sunday"))
{ n=0; m=0; }
else if(list.get(i).equals("Monday"))
{ n=1; m=0; }
else if(list.get(i).equals("Tuesday"))
{ n=2; m=0; }
else if(list.get(i).equals("Wednesday"))
{ n=3; m=0; }
else if(list.get(i).equals("Thursday"))
{ n=4; m=0; }
else
{
cell_value[m][n]=list.get(i);
m++;
}
}
} catch (IOException e) {
e.printStackTrace();
}
Container contentPane = this.getContentPane();
setTitle("Activity Screen");
setSize(1000, 500);
JTable table = new JTable(cell_value, ColName);
JLabel lblTitle = new JLabel("Activities");
lblTitle.setFont(new java.awt.Font("Arial", 1, 24));
JButton btnSave = new JButton("Save");
JButton btnView = new JButton("View");
JButton btnAdd = new JButton("Add");
JButton btnRemove = new JButton("Remove");
JButton btnBack = new JButton("Back");
btnBack.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
//Execute when button is pressed
StartUpFrame SUF = new StartUpFrame();
SUF.setVisible(true);
setVisible(false);
}
});
btnView.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
ViewActivity VA = new ViewActivity();
VA.setVisible(true);
}
});
btnAdd.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
AddActivity AA = new AddActivity();
AA.setVisible(true);
}
});
//Lay out the label and scroll pane from top to bottom.
contentPane.add(lblTitle, BorderLayout.PAGE_START);
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
table.setAlignmentX(Component.CENTER_ALIGNMENT);
contentPane.add(Box.createRigidArea(new Dimension(0,20)));
contentPane.add(table);
add(new JScrollPane(table));
//Lay out the buttons from left to right.
JPanel buttonPane = new JPanel();
buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
buttonPane.add(Box.createHorizontalGlue());
buttonPane.add(btnSave);
buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
buttonPane.add(btnView);
buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
buttonPane.add(btnAdd);
buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
buttonPane.add(btnRemove);
buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
buttonPane.add(btnBack);
contentPane.add(buttonPane, BorderLayout.PAGE_END);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
table.setCellSelectionEnabled(true);
}
}
class ActivityScreen
{
public static void main(String[] args)
{
new MyFrame();
}
}
的days.dat文件
Sunday
Advanced Open Water Dive Certificate
Sailing
Generation Next
Monday
Helping Hands
Beach Touch Rugby
Running Club
Yoga Club
Tennis Lessons
Tuesday
Recycling Club
Best Buddies
Crochet Club
Movie Club
Shooting Club
Wednesday
Table Tennis
Modern Dance
Contemporary Dance
Gavel Club
Thursday
Cooking
Gym Training
所以我加了這個代碼:List list = Collections.synchronizedList(new LinkedList()); 但錯誤仍然存在 –
Geuni
2013-03-09 06:45:56
您還需要將其列入列表:列表 list = Collections.synchronizedList(new LinkedList ()); –
2013-03-09 13:28:16