小编tro*_*guy的帖子

imageio.IIOException:无法读取输入文件

我一周前开始使用Java,现在我想在窗口中插入一个图像.无论我尝试什么,我都在Eclipse中继续这样做: javax.imageio.IIOException:无法读取输入文件!

package graphics;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;
import src.Common;

public class Window extends JFrame
{
public class Panel extends JPanel
{

    public void paintComponent(Graphics g)
    {
        Image img; 
        try 
        {
        img = ImageIO.read(new File("/logo.jpg"));
        g.drawImage(img, 0, 0, this);
        } 
        catch (IOException e) 
        {
        e.printStackTrace();
        }

    }
}

public Window(String title, int width, int height)
{
    this.setTitle(title);
    this.setSize(width, height);
    this.setLocationRelativeTo(null);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setContentPane(new Panel()); 
    this.setVisible(true);
}
Run Code Online (Sandbox Code Playgroud)

}

我认为代码非常自我解释.我试图用这个 …

java image

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

使用JFreechart(bar,XY)绘制多个绘图

你好我必须制作一个显示功率曲线的程序,因此我需要在一个窗口上显示三个不同的图.不同类型的图是XY(只是点),条形和XY线.

我的问题:不知怎的,我只能获得两个图表来绘制,我无法正确更改单个图表的颜色.

编辑:当我把第三张图表的声明作为评论时,第二张图最终被绘制出来.绘制三张图表是不可能的吗?

任何帮助将不胜感激,谢谢;)

import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.NumberTickUnit;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.DatasetRenderingOrder;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYBarRenderer;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.xy.IntervalXYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.ui.ApplicationFrame;


public class OverlaidPlot extends ApplicationFrame 
{
   final XYSeries series0 = new XYSeries("Graph0");
   final XYSeries series1 = new XYSeries("Graph1");
   final XYSeries series2 = new XYSeries("Graph2");

   public OverlaidXYPlotDemo(final String title) 
    {
       super(title);
       final JFreeChart chart = createOverlaidChart();
       final ChartPanel panel = new ChartPanel(chart, true, true, true, true, true);
       panel.setPreferredSize(new …
Run Code Online (Sandbox Code Playgroud)

java plot jfreechart

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

错误:没有''成员函数在类中声明''

我正在尝试创建一个包含虚函数的类,我想在两个子类中继承它.

我知道有些人已经问过这个(例如这里那里),但我无法理解答案.

所以我做了一个我正在尝试的简化示例代码:

//Mother .h file 

#ifndef _MOTHER_H_
#define _MOTHER_H_
#include <iostream>

class Mother
{
 protected :
   std::string _name;
 public:
   Mother(std::string name);
   ~Mother();
   virtual std::string getName() = 0; 
};

#endif

//Mother .cpp file

#include "Mother.h"

Mother::Mother(std::string name)
{
  this->_name = name; 
}

Mother::~Mother()
{
}


//Child.h file

#ifndef _CHILD_H_
#define _CHILD_H_
#include "Mother.h"

class Child : public Mother
{
 private : 
   std::string _name;
 public:
   Child(std::string name);
   ~Child();
};

#endif


//Child .cpp file

#include "Mother.h"
#include "Child.h" …
Run Code Online (Sandbox Code Playgroud)

c++ virtual inheritance class

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

启用另一个按钮禁用一个按钮,反之亦然

当我点击按钮A(和相反的情况)时,我希望能够禁用按钮B.

我的问题是,一旦按钮A启用,按钮B被禁用(这没关系)但是当我禁用按钮A时,按钮B保持禁用状态.

我怎么能解决这个问题?

这是我为帮助理解问题而做的一个例子:

package test;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.wb.swt.SWTResourceManager;

public class Buttons 
{
    protected static Shell shell;

    protected static void createContents() 
    {
       // Creation of the window
       shell = new Shell();
       shell.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
       shell.setSize(800, 600);
       shell.setText("Test");
       shell.setLayout(null);

       // Creation of the background canvas
       Canvas area1 = new Canvas(shell, SWT.NONE);
       area1.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
       area1.setBounds(82, 119, 597, 393);
       buttons(area1);
    }
    public static void buttons(Canvas area1)
    {
       // Creation of the canvas to …
Run Code Online (Sandbox Code Playgroud)

java swt button

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

标签 统计

java ×3

button ×1

c++ ×1

class ×1

image ×1

inheritance ×1

jfreechart ×1

plot ×1

swt ×1

virtual ×1