box layout DEMO

package HeadFirstJava;
import javax.swing.*;
import java.awt.*;

public class Panel1 {
    public static void main(String[] args) {
        Panel1 gui = new Panel1();
        gui.go();
    }
    public void go() {
        JFrame frame = new JFrame();
        JPanel panel = new JPanel();
        panel.setBackground(Color.darkGray);
        
        panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
        
        // panel's default layout manager is 'flow layout'
        // but we change it to 'box layout'
        JButton button = new JButton("shock me");
        JButton buttonTwo = new JButton("bliss");
        panel.add(button);
        panel.add(buttonTwo);
        
        
        frame.getContentPane().add(BorderLayout.EAST, panel);
        frame.setSize(200, 200);
        frame.setVisible(true);
   }
}


以下是一个简单的 QEMU GTK GUI 应用程序的示例代码: ```c #include <gtk/gtk.h> #include <glib.h> #include <stdlib.h> #include <stdio.h> #include <string.h> #include "qemu/qemu.h" #include "qemu/qemu-option.h" GtkWidget *window; GtkWidget *start_button; GtkWidget *stop_button; GtkWidget *console_text; QEMUOption option; static void on_start_button_clicked(GtkWidget *widget, gpointer data) { char *cmd = g_strdup_printf("qemu-system-%s -hda %s", option.arch, option.disk_image); FILE *fp = popen(cmd, "r"); if (fp == NULL) { perror("popen failed"); return; } char buf[1024]; while (fgets(buf, sizeof(buf), fp) != NULL) { gtk_text_buffer_insert_at_cursor(gtk_text_view_get_buffer(GTK_TEXT_VIEW(console_text)), buf, strlen(buf)); } pclose(fp); } static void on_stop_button_clicked(GtkWidget *widget, gpointer data) { // TODO: Stop the QEMU process } static void on_window_destroy(GtkWidget *widget, gpointer data) { gtk_main_quit(); } int main(int argc, char *argv[]) { gtk_init(&argc, &argv); // Initialize the QEMU option option.arch = "x86_64"; option.disk_image = "/path/to/disk_image.img"; // Create the main window window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(window), "QEMU GUI"); gtk_window_set_default_size(GTK_WINDOW(window), 640, 480); g_signal_connect(window, "destroy", G_CALLBACK(on_window_destroy), NULL); // Create the start button start_button = gtk_button_new_with_label("Start QEMU"); g_signal_connect(start_button, "clicked", G_CALLBACK(on_start_button_clicked), NULL); // Create the stop button stop_button = gtk_button_new_with_label("Stop QEMU"); g_signal_connect(stop_button, "clicked", G_CALLBACK(on_stop_button_clicked), NULL); // Create the console text view console_text = gtk_text_view_new(); gtk_text_view_set_editable(GTK_TEXT_VIEW(console_text), FALSE); gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(console_text), GTK_WRAP_WORD_CHAR); // Create a vertical box layout GtkWidget *vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5); gtk_container_add(GTK_CONTAINER(window), vbox); // Add the start button to the layout gtk_box_pack_start(GTK_BOX(vbox), start_button, FALSE, FALSE, 0); // Add the stop button to the layout gtk_box_pack_start(GTK_BOX(vbox), stop_button, FALSE, FALSE, 0); // Add the console text view to the layout GtkWidget *scroll = gtk_scrolled_window_new(NULL, NULL); gtk_container_add(GTK_CONTAINER(scroll), console_text); gtk_box_pack_start(GTK_BOX(vbox), scroll, TRUE, TRUE, 0); // Show all widgets gtk_widget_show_all(window); // Enter the GTK main loop gtk_main(); return 0; } ``` 该示例代码仅包含了启动和停止 QEMU 的基本逻辑,并没有对 QEMU 进行更高级的配置和控制。你可以根据需要修改代码,并添加其他功能来完善你的 QEMU GTK GUI 应用程序。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值