public void getParam(){
frameX = Integer.parseInt(props.getProperty("top"));
frameY = Integer.parseInt(props.getProperty("left"));
frameWidth = Integer.parseInt(props.getProperty("width"));
frameHeight = Integer.parseInt(props.getProperty("height"));
}
public void setParam(){
props.setProperty("top", frameX + "");
props.setProperty("left", frameY + "");
props.setProperty("width", frameWidth + "");
props.setProperty("height", frameHeight + "");
}
public void doClosing(){
if(change == true){
int result = JOptionPane.showConfirmDialog(null, "文件被改动了,请注意保存文件!",
"注意", JOptionPane.OK_CANCEL_OPTION);
if(result == JOptionPane.OK_OPTION){
if(fileName != null)
writeFile(fileName);
saveAsFileDialog.show();
fileName = saveAsFileDialog.getDirectory()+saveAsFileDialog.getFile();
if (fileName!= null)
writeFile(fileName);
}
}
frameX = getX();
frameY = getY();
frameWidth = getWidth();
frameHeight = getHeight();
setParam();
try{
savaConfig();
}catch(Exception ex){
ex.printStackTrace();
}
System.exit(1);
}
public void doOpening(){
try{
loadConfig();
getParam();
}catch(Exception ex){
ex.printStackTrace();
}
setLocation(frameX, frameY);
setSize(frameWidth, frameHeight);
}
public void readFile(String fileName){
try{
textArea.setText("");
File file = new File(fileName);
BufferedReader breader = new BufferedReader(new FileReader(file));
while(true){
str = breader.readLine();
if(str == null)
break;
textArea.append(str + "\n");
change = false;
}
}catch(IOException e){
System.out.println("不能打开文件");
}
}
public void writeFile(String fileName){
try{
File file = new File (fileName);
FileWriter writeOut = new FileWriter(file);
writeOut.write(textArea.getText());
writeOut.close();
change = false;
}catch(IOException e){
System.out.println("存储文件错误");
}
}
public void setLookAndFeel(int index){
try {
UIManager.setLookAndFeel(lafArray[index]);
} catch (Exception exc) {
System.err.println("Error loading " + lafArray[index] + ": " + exc);
}
}
private void theSetToolTipText(){
newItem.setToolTipText("新建一个文件");
}
}
frameX = Integer.parseInt(props.getProperty("top"));
frameY = Integer.parseInt(props.getProperty("left"));
frameWidth = Integer.parseInt(props.getProperty("width"));
frameHeight = Integer.parseInt(props.getProperty("height"));
}
public void setParam(){
props.setProperty("top", frameX + "");
props.setProperty("left", frameY + "");
props.setProperty("width", frameWidth + "");
props.setProperty("height", frameHeight + "");
}
public void doClosing(){
if(change == true){
int result = JOptionPane.showConfirmDialog(null, "文件被改动了,请注意保存文件!",
"注意", JOptionPane.OK_CANCEL_OPTION);
if(result == JOptionPane.OK_OPTION){
if(fileName != null)
writeFile(fileName);
saveAsFileDialog.show();
fileName = saveAsFileDialog.getDirectory()+saveAsFileDialog.getFile();
if (fileName!= null)
writeFile(fileName);
}
}
frameX = getX();
frameY = getY();
frameWidth = getWidth();
frameHeight = getHeight();
setParam();
try{
savaConfig();
}catch(Exception ex){
ex.printStackTrace();
}
System.exit(1);
}
public void doOpening(){
try{
loadConfig();
getParam();
}catch(Exception ex){
ex.printStackTrace();
}
setLocation(frameX, frameY);
setSize(frameWidth, frameHeight);
}
public void readFile(String fileName){
try{
textArea.setText("");
File file = new File(fileName);
BufferedReader breader = new BufferedReader(new FileReader(file));
while(true){
str = breader.readLine();
if(str == null)
break;
textArea.append(str + "\n");
change = false;
}
}catch(IOException e){
System.out.println("不能打开文件");
}
}
public void writeFile(String fileName){
try{
File file = new File (fileName);
FileWriter writeOut = new FileWriter(file);
writeOut.write(textArea.getText());
writeOut.close();
change = false;
}catch(IOException e){
System.out.println("存储文件错误");
}
}
public void setLookAndFeel(int index){
try {
UIManager.setLookAndFeel(lafArray[index]);
} catch (Exception exc) {
System.err.println("Error loading " + lafArray[index] + ": " + exc);
}
}
private void theSetToolTipText(){
newItem.setToolTipText("新建一个文件");
}
}
[email protected]
JTextArea myArea = ??;
myArea.getDocument().addDocumentListener(myListener);
第三个问题,你要监听鼠标右键,相应单击动作
获取鼠标坐标,然后根据坐标new frame()就好了我只知道这些,可能有更好的方法
第二个问题,需要加一句话!
SwingUtilities.updateComponentTreeUI(this);但是我郁闷的就是,我遇到这样的问题的时候,我怎么找才能知道要加这句话,我根本不可能想到,也不可能轻易的找到是需要加这一句话,郁闷!