小编moo*_*les的帖子

使用JFileChooser打开文件

作为一个小小的项目,我认为制作文本编辑器会很酷.我目前只是打开文件了.这是我打开文件的代码(eActionEvent,open是a JMenuItem):

else if (e.getSource() == open) {
        JFileChooser choice = new JFileChooser();
        int option = choice.showOpenDialog(this);
        if (option == JFileChooser.APPROVE_OPTION) {
            try{
                Scanner scan = new Scanner(new FileReader((open).getSelectedFile().getPath()));
            }
        }

    }
Run Code Online (Sandbox Code Playgroud)

试块给了我麻烦.Eclipse说的getSelectedFile()是类型未定义JMenuItem.对于MenuItems来说,它似乎也是未定义的.有没有其他方法可以解决这个问题,还是另一种方法可以解决这个问题?

java swing jfilechooser file

6
推荐指数
1
解决办法
3万
查看次数

在println语句中使用字符串和变量

我正在编写一个程序,通过询问用户的英寸和英尺高度来找到用户的理想体重.到目前为止,除了最终陈述之外,一切看起来都不错,其中我向用户返回男性和女性的平均体重,并告诉他们他们的体重范围在15%之间.这是给我一个问题的代码:

System.out.println("For a male, the height " + foot "' " +
                   inches + "/""" + " and it's ideal weight is " + 
                   mWeight + "lbs. Anything between " + minMaleLb +
                   "lbs and " + maxMaleLb + "lbs is okay.");
System.out.println("For a female, the height " + foot "' " +
                   inches + "/""" + " and it's ideal weight is " + 
                   fWeight + "lbs. Anything between " + minFeMaleLb +
                   "lbs and " + maxFeMaleLb + …
Run Code Online (Sandbox Code Playgroud)

java

4
推荐指数
2
解决办法
4万
查看次数

你如何将 Fortran 的复杂类型传递给 C#?

假设我有以下 Fortran 代码

subroutine COMPLEX_PASSING(r, i, c)
    !DEC$ ATTRIBUTES DLLEXPORT::COMPLEX_PASSING

    REAL*8 :: r, i
    COMPLEX*8 :: c

   c = cmplx((r * 2), (i * 2))

return
end
Run Code Online (Sandbox Code Playgroud)

Fortran 代码是用

gfortran -c complex_passing.f90
gfortran -fPIC -shared -o complex_passing.dll complex_passing.o
Run Code Online (Sandbox Code Playgroud)

我如何在 C# 中调用这个子程序?我尝试了以下代码:

gfortran -c complex_passing.f90
gfortran -fPIC -shared -o complex_passing.dll complex_passing.o
Run Code Online (Sandbox Code Playgroud)

收效甚微 - 我的 COMPLEX 结构似乎正在返回垃圾数据:

Real: 134217760.5
Imaginary: 0
Run Code Online (Sandbox Code Playgroud)

当我期望实部为 8,虚部为 20 时。

c# pinvoke fortran gfortran

4
推荐指数
1
解决办法
50
查看次数

在读取文件数据时使用子字符串

昨晚我问了这样一个问题,我不确定发生了什么,我遇到了另一个问题,所以这里有:

我的教练给了我的课程一个项目,一个程序读取文件,读取每个字母,然后打印出每个行所有的点击,出局,走路和牺牲苍蝇的数量.我在关于此主题的原始问题中发布了更多信息.我已经重写了代码,我更有机会让程序运行起来.我了解了什么是子串,还有更多关于令牌的知识,并且与这个程序结合在一起:

import java.util.Scanner;
import java.io.*;

public class BaseballStats
{
  public static void main(String[]args) throws IOException
  {
    Scanner fileScan, lineScan;
    String fileName;
    int oCount = 0, hCount = 0, sCount = 0, wCount = 0;
    Scanner scan = new Scanner(System.in);

    System.out.print("Enter the name of the input file: ");
    fileName = scan.nextLine();
    fileScan = new Scanner(new File(fileName));

    while (fileScan.hasNext())
    {
      lineScan = new Scanner (fileName);
      lineScan.useDelimiter(",");

      String input = lineScan.nextLine();
      int point =(input.indexOf(","));

      String name = input.substring(0,point);
      String records …
Run Code Online (Sandbox Code Playgroud)

java

1
推荐指数
1
解决办法
5223
查看次数

标签 统计

java ×3

c# ×1

file ×1

fortran ×1

gfortran ×1

jfilechooser ×1

pinvoke ×1

swing ×1