本帖最初由 鸿受 于 2020-12-11 22:56 编纂
正在eclipse编译,毛病提醒:Exception in thread "main" java.lang.Error: Unresolved compilation problem:
package demo;
import java.text.Format;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import javax.xml.crypto.Data;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
public class demo extends JFrame
{
private JScrollPane scrollPane;
private JPanel jContenPanel = null;
private JTextArea jTextArea = null;
private JPanel controlPanel = null;
private JButton OpenButton = null;
private JButton CloseButton = null;
private Object ;
private JTextArea geTextArea()
{
if(jTextArea == null)
{
jTextArea = new JTextArea();
}
return jTextArea;
}
private JPanel getControlPanel()
{
if(controlPanel == null)
{
FlowLayout flowLayout = new FlowLayout();
flowLayout.setVgap(1);
controlPanel = new JPanel();
controlPanel.setLayout(flowLayout);
controlPanel.add(getOpenButton(), null);
controlPanel.add(getCloseButton(), null);
}
return controlPanel;
}
private JButton getOpenButton()
{
if(OpenButton == null)
{
OpenButton = new JButton();
OpenButton.setText("写进");
OpenButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
File file = new File("text.txt");
try
{
FileWriter out = new FileWriter(file);
String string = jTextArea.getText();
out.write(string);
out.close();
} catch (Exception e2)
{
// TODO: handle exception
e2.printStackTrace();
}
}
});
}
return OpenButton;
}
private JButton getCloseButton()
{
if(CloseButton == null)
{
CloseButton = new JButton();
CloseButton.setText("读与");
CloseButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
File file = new File("text.txt");
try
{
FileReader in = new FileReader(file);
char byt[] = new char[1024];
int len = in.read(byt);
jTextArea.setText(new String(byt, 0, len));
in.close();
} catch (Exception e2)
{
// TODO: handle exception
e2.printStackTrace();
}
}
});
}
return CloseButton;
}
public demo()
{
super();
Init();
}
private void Init()
{
this.setSize(300, 200);
this.setContentPane(getJContentPane());
this.setTitle("读写文件");
}
private JPanel getJContentPane()
{
if(jContenPanel == null)
{
jContenPanel = new JPanel();
jContenPanel.setLayout(new BorderLayout());
jContenPanel.add(getScrollPanel(), BorderLayout.CENTER);
jContenPanel.add(controlPanel, BorderLayout.SOUTH);
}
return jContenPanel;
}
public static void main(String[] args)
{
demo thisclass = new demo();
thisclass.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
thisclass.setVisible(true);
}
protected JScrollPane getScrollPanel()
{
if(scrollPane == null)
{
scrollPane = new JScrollPane();
scrollPane.setViewportView(geTextArea());
}
return scrollPane;
}
}
|