小编dan*_*nn_的帖子

编译器在前向结构声明中给出错误

我有一个这样的代码,我不能把"struct node"放在"struct mnode"之上所以我把它声明在顶部,如下所示.
但是编译器说字段n的类型不完整.
如何在顶部正确声明一个结构?

struct node;
struct mnode{
    int j;
    node n;
};
struct node{
    int k;
};
Run Code Online (Sandbox Code Playgroud)

c++ struct

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

绘制直方图时如何更改矩形的大小?

其实我是java gui的新手,在这里我想改变矩形高度每当我们把东西放在文本字段并按下按钮,但我不知道怎么做,实际上我查了一大堆但是我不能找不到简单的方法.实际上我找不到如何更改MyPanel类中paintComponent内部的矩形大小.

(高度变化的逻辑是元首和小的元音,以及字符串中的组成和其他东西)

import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Hist{
    int h1=0,h2=0,h3=0,h4=0,h5=0;
    JFrame f=new JFrame();
    JButton b=new JButton("click");
    JTextField text=new JTextField(30);


public static void main(String args[]){
    Hist h=new Hist();

}

Hist(){

    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setLayout(new FlowLayout());
    f.add(new MyPanel(h1,h2,h3,h4,h5));
    f.setSize(400,300);
    f.setVisible(true);

    f.add(b);
    f.add(text);

    thehandler handler=new thehandler();
    b.addActionListener(handler);

}
class thehandler implements ActionListener{
    public void actionPerformed(ActionEvent event){
        if(event.getSource()==b){
            h1=0;h2=0;h3=0;h4=0;h5=0;
            String s;
            s=text.getText();
            char[] ar=s.toCharArray();
            for(int i=0;i<s.length();i++){
                if(ar[i]=='a'||ar[i]=='e'||ar[i]=='i'||ar[i]=='o'||ar[i]=='u'){
                    h1=h1+10;
                }
                else if(ar[i]=='A'||ar[i]=='E'||ar[i]=='I'||ar[i]=='O'||ar[i]=='U'){
                    h2=h2+10;
                }
                else{
                    h5=h5+10;
                }
            }

        }
    }

 } …
Run Code Online (Sandbox Code Playgroud)

java graphics user-interface swing paint

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

标签 统计

c++ ×1

graphics ×1

java ×1

paint ×1

struct ×1

swing ×1

user-interface ×1