我想把我的背景图像放在这个框架的最底部,按钮放在顶部.但是我在下面写的代码不起作用.任何人都可以看到问题出在哪里?
另一件事是,即使我为我的按钮设置了位置,它仍然显示在框架的顶部中心.
请忽略评论行.(我只是在猜测,并希望它们可以工作,但它们显然没有.)
public class Menu extends JFrame{
private JLayeredPane pane;
private JLayeredPane pane2;
public Menu(){
final JFrame f = new JFrame("Chinese Chess");
JButton play = new JButton("Play vs. AI");
f.setLayout(new FlowLayout());
f.setLocationRelativeTo(null);
f.setSize(800, 800);
f.setVisible(true);
f.setResizable(false);
//f.pack();
pane = new JLayeredPane();
pane2 = new JLayeredPane();
f.add(pane);
f.add(pane2);
//background image
JLabel background = new JLabel(new ImageIcon("res/img/background.png"));
background.setLocation(0, 0);
background.setSize(800, 800);
pane.add(background, JLayeredPane.FRAME_CONTENT_LAYER);
pane2.add(play, JLayeredPane.DEFAULT_LAYER);
//pane.moveToBack();
//button PlayAI
play.setLocation(500,500);
play.setPreferredSize(new Dimension(100,50));
//f.setLayout(new FlowLayout());
//frame menu
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//f.getContentPane().add(play);
play.addActionListener(new ActionListener() {
public …Run Code Online (Sandbox Code Playgroud) 我对react-router-dom v6的使用变化感到非常困惑。根据他们的文档,我们可以简单地将 Route 组件传递到 element 属性中,但我收到此错误
Uncaught TypeError: meta.relativePath.startsWith is not a function
Run Code Online (Sandbox Code Playgroud)
我找不到任何解决方案。
import React from 'react';
import { Routes, Route, Navigate } from "react-router-dom";
import { Results } from './Results';
export const Catogories = () => {
return (
<div className='p-4'>
<Routes>
<Route exact path='/' element={<Navigate to='/search' />} />
<Route exact path={["/search", '/images,', '/news', '/videos']} element={<Results />} />
</Routes>
</div>
);
};
Run Code Online (Sandbox Code Playgroud) 我刚刚开始学习CSS模块的使用。
我想做的是创建一个滑块,如何实现其功能是通过使用“activeSlide”、“nextSlide”和“lastSlide”动态更改我的 className。但是,我对 CSS 模块有一个问题,我不知道在 className 中放入什么内容以进行动态定位并同时应用与每个位置相对应的 CSS 属性。我如何使用 CSS 模块在一个 className 中实现这两种功能。
这是我的 index.jsx 文件,
import React, { useState, useEffect } from 'react';
import {FiChevronRight, FiChevronLeft} from 'react-icons/fi';
import reviewdata from './reviewdata';
import styles from './index.module.css';
export default function Review(){
const randomizer =()=>{
let number = Math.floor(Math.random()* (people.length))
return number;
}
const [people, setPeople]= useState(reviewdata);
const [index, setIndex] = useState(randomizer());
useEffect(()=>{
const lastIndex = people.length - 1;
if (index < 0){
setIndex(lastIndex);
}
if (index > lastIndex){
setIndex(0);
} …Run Code Online (Sandbox Code Playgroud)